L
Larry.Martell
I have a JTextArea wrapped in a JScrollPane, and when I append a line
to the text area
I want the scroll bar to adjust so that the new line is seen in the
viewport. I have
some code that seems to work most of the time, but every once in a
while it does
not work properly. I think I'm probably not doing this the right way.
Here's a code
snippet that shows what I'm doing:
JPanel consolePane = new JPanel();
JTextArea consoleTextArea = new JTextArea(35, 65);
JScrollPane consoleScrollPane = new JScrollPane(consoleTextArea);
JScrollBar vsb = consoleScrollPane.getVerticalScrollBar();
When I want to update the text I do this:
consoleTextArea.append(line);
consoleTextArea.append("\n");
vsb.setMaximum(vsb.getMaximum()+1);
vsb.setValue(vsb.getMaximum()+1);
Seems like there must be an easier way to do this. Is there some
attribute that
I can set that will make this happen automagically?
TIA!
-larry
to the text area
I want the scroll bar to adjust so that the new line is seen in the
viewport. I have
some code that seems to work most of the time, but every once in a
while it does
not work properly. I think I'm probably not doing this the right way.
Here's a code
snippet that shows what I'm doing:
JPanel consolePane = new JPanel();
JTextArea consoleTextArea = new JTextArea(35, 65);
JScrollPane consoleScrollPane = new JScrollPane(consoleTextArea);
JScrollBar vsb = consoleScrollPane.getVerticalScrollBar();
When I want to update the text I do this:
consoleTextArea.append(line);
consoleTextArea.append("\n");
vsb.setMaximum(vsb.getMaximum()+1);
vsb.setValue(vsb.getMaximum()+1);
Seems like there must be an easier way to do this. Is there some
attribute that
I can set that will make this happen automagically?
TIA!
-larry