0

I'm creating a java chat application using jFrame. I'm using a JScrollPane to scroll the text area. All the new messages are added at the bottom, but the scroll bar starts at the top. How do I make it start at the bottom?

mKorbel
  • 109,107
  • 18
  • 130
  • 305
g3nair
  • 127
  • 5
  • possible duplicate of [How to set AUTO-SCROLLING of JTextArea in Java GUI?](http://stackoverflow.com/questions/1627028/how-to-set-auto-scrolling-of-jtextarea-in-java-gui) – Jason C Mar 29 '14 at 09:07

1 Answers1

1

You can force it to scroll to the bottom after adding a message by scrolling its vertical scrollbar directly, e.g.:

JScrollBar vScrollBar = myScrollPane.getVerticalScrollBar();
vScrollBar.setValue(vScrollBar.getMaximum());
Jason C
  • 35,986
  • 14
  • 111
  • 162