How to set a scrollbar at the top?!?!?!

How do I get a scrollbar to start at the top - right now it is at the bottom of the text field when the JDialog is opened (A silly defaul if you ask me - why would it start as the bottom of a text area?!)

JTextArea limitInfoText =new JTextArea(LIMIT_INFO, 8, 25);

limitInfoText.setEditable(false);

limitInfoText.setLineWrap(true);

limitInfoText.setWrapStyleWord(true);

limitInfoText.setMargin(new Insets(5, 3, 5, 3));

limitInfoText.setToolTipText("Limit information");

JScrollPane limitInfoScroll =new JScrollPane(limitInfoText);

infoPane.add(limitInfoScroll);

// ....

this.getContentPane().add(infoPane, BorderLayout.CENTER);

[1001 byte] By [Hahzez] at [2007-9-26 19:52:38]
# 1

When you insert into a text component, the caret, whether the component editable or not, is set to the end of the text inserted. The scroll pane adjusts it position based on the caret.

You have two options, set the caret position to 0:

limitInfoText.setCaretPosition(0);

or get the scroll bar and set its value to 0:

limitInfoScroll.getVerticalScrollBar().setValue(0);

Hope this helps.

sfeveile at 2007-7-3 13:09:24 > top of Java-index,Archived Forums,Swing...