Re: JScrollBar problems



I am trying to force the scrolling to show the top of what I have just
generated in a JTextArea.

JTextArea howTo =
new JTextArea( ... );
howTo.setForeground( BLACK );
howTo.setMargin( new Insets( 5, 5, 5, 5 ) );
howToScroller =
new JScrollPane( howTo,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
....

howTo.setText( ... );

// make sure top of generated code is visible.
final JScrollBar v = howToScroller.getVerticalScrollBar();
v.setValue( v.getMinimum() );

Yet it ignores me. It acts as if I had said v.getMaximum() showing the
END of the text instead of the beginning.

mystery solved. This might be considered a bug in sun.

There is how I got it to work:

// invoke later to give time for text to render.
SwingUtilities.invokeLater( new Runnable() {
public void run()
{
final JScrollBar v =
howToScroller.getVerticalScrollBar();
v.setValue( v.getMinimum() );
}
} );
The key is, the setText had to RENDER before the setValue was
processed.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.



Relevant Pages

  • Re: JScrollBar problems
    ... generated in a JTextArea. ... JTextArea howTo = ... final JScrollBar v = howToScroller.getVerticalScrollBar; ... the setText had to RENDER before the setValue was ...
    (comp.lang.java.gui)
  • JScrollBar problems
    ... I am trying to force the scrolling to show the top of what I have just ... generated in a JTextArea. ... JTextArea howTo = ... new JScrollPane(howTo, ...
    (comp.lang.java.gui)