Menu

#544 Scanner input boxes wrap when Interaction scrollbar appears

2: Annoying
closed
nobody
5
2007-02-03
2006-10-17
Marty Stepp
No

Using DrJava 20060918-1737 on Windows and Linux,
there's an annoying UI appearance bug with user input
from the Scanner.

Often we'll write programs where we prompt the user
using System.out.print, and then read a value using the
Scanner. For example:

Scanner console = new Scanner(System.in);
System.out.print("Your name? ");
String name = console.nextLine();

Notice that I used print, not println -- we use print
intentionally to stay on the same line as the user's
input. DrJava handles this just fine, except at the
moment that the Interactions pane becomes just large
enough to need a scrollbar.

As the scrollbar appears, it causes the lines of the
interactions pane to re-wrap or something, making the
input entry box jump down to the next line. This is
frustrating for students because they think their
program has inserted a line break that it has not.
They're required to exactly match expected output, so
they understandably get worried when they encounter
this bug.

To reproduce this bug, run a program such as the
attached program. Before running it, resize the
interaction pane to give yourself some room, say 8-10
lines. Initially the prompts will look right, but as
there become just enough prompts to cause a scrollbar
to appear on the Interactions pane, every input textbox
will suddenly shift in position to the next line. It's
incorrect and ugly.

Discussion

  • Marty Stepp

    Marty Stepp - 2006-10-17

    short Java program to demonstrate this bug

     
  • Mathias Ricken

    Mathias Ricken - 2006-10-18

    Logged In: YES
    user_id=1075744

    The problem is that the input box (which is a subclass of
    JTextArea) has to be rectangular, so when the text gets too
    long and the line in the Interactions Pane wraps, the entire
    input box moves to the next line. The input box then fills
    the available space in that new line and consumes the entire
    width of the Interactions Pane, which makes it look like
    there is a line break before the input box, even though
    there isn't.

    I think the optimal behavior that we can achieve is that the
    input box remains on the line where it originally was and
    only uses its original width, i.e. text that has wrapped to
    the next line appears "indented"; the space beneath the text
    to the left of the input box will remain empty.

    To achieve this, I have tried to limit the maximum width of
    the input box as returned by getMaximumSize(). This has
    prevented the input box from consuming the entire width, but
    as soon as it needs two lines of text, it still wraps to the
    beginning of the next line. I don't know why, and I don't
    know the Swing text document API well enough. It was lucky
    enough to figure out how to fix the problem with the input
    box disappearing when the user stepped through the program
    with the debugger.

    I would also like to point out that it will be impossible to
    prevent the input box from being on the next line in all
    cases: In the worst case, the text to the left of the input
    box will consume the entire line except for one character.
    If we want to prevent input boxes that are only a character
    wide, we will have to set a minimum width, and in that case,
    the text box will have to be on the next line.

     
  • Nobody/Anonymous

    Logged In: NO

    Mathias,

    Thank you for your reply. I believe we are talking about
    two different things. Your message was talking about the
    case where the user input textbox appears and I type a very
    long string into it. As you say, the textbox expands to a
    second line. This seems like reasonable behavior and does
    not bother me.

    The case I'm describing is different. I'm talking about the
    physical position of the textbox moving to the next line at
    the moment where the overall interactions pane requires a
    scrollbar. One way to reproduce this bug is to load DrJava
    and type the following lines into the interactions pane:

    import java.util.*;
    Scanner c = new Scanner(System.in);
    System.out.print("Input? "); s = c.nextLine();

    Notice that the input box appears on the same line as the
    "Input? " prompt. Now, without entering any text, resize
    the interactions pane by dragging the vertical divider at
    its top. Shrink the interactions pane to various sizes such
    that its entire contents do not fit in the viewable area. A
    scrollbar will appear on the right side of the interactions
    pane (which is fine), but, the input textbox will jump to
    the next line!

    You might say, why should a person be resizing their
    interactions pane while the program is running, anyway? But
    the bug doesn't only occur when resizing. It also occurs if
    you're running a program with several prompt/inputs, whose
    output initially doesn't need as scrollbar but eventually
    becomes long enough that it does. Suddenly, just as the
    interactions pane scrollbar appears, all the previous input
    textboxes wrap to the next line. This is undesirable
    because it makes our students think they've inserted a stray
    println statement or otherwise inserted an erroneous line break.

     
  • Marty Stepp

    Marty Stepp - 2006-10-20

    screenshot before wrapping occurs

     
  • Marty Stepp

    Marty Stepp - 2006-10-20

    screenshot after wrapping occurs

     
  • Marty Stepp

    Marty Stepp - 2006-10-20

    Logged In: YES
    user_id=1610546

    That last post by "nobody" was me; I'd forgotten to log in.
    I have now also attached two screenshots of the bug.

     
  • Mathias Ricken

    Mathias Ricken - 2006-10-20

    Logged In: YES
    user_id=1075744

    Thanks for the detailed explanation; I understand the
    problem now, even though I don't yet know how to fix it.

    The input box somehow never shrinks. When the scrollbar
    appears, the space becomes too small fo the input box, so it
    wraps to the next line. There, it expands to fill the entire
    width of the Interactions Pane, so even when the scrollbar
    disappears, it remains too big and therefore on the next line.

    Fixing the width to prevent the input box from expanding
    beyond its original width helps a little bit: Input boxes
    that were created when the scrollbar was visible stay in
    their correct place, but those created when the scrollbar
    was not there still move to the next line; however, if the
    scrollbar disappears, they snap back to where they shou;d be.

    I'll have to play around a little, but I'm confident we'll
    have this problem removed pretty soon.

    Thanks for helping us make DrJava better!

    --Mathias

     
  • Robert Cartwright

    Logged In: YES
    user_id=430590
    Originator: NO

    We took the easy way out and simply configured the window to always include the scroll bar.

    I am closing this bug.

     
  • Robert Cartwright

    • status: open --> closed
     

Log in to post a comment.