Re: JScrollBar problems
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 27 Jul 2007 09:51:06 GMT
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
.
- Follow-Ups:
- Re: JScrollBar problems
- From: Knute Johnson
- Re: JScrollBar problems
- References:
- JScrollBar problems
- From: Roedy Green
- JScrollBar problems
- Prev by Date: JSplitPane divider component and JPopupMenu panel
- Next by Date: Swing application getting affected by screen resolution
- Previous by thread: Re: JScrollBar problems
- Next by thread: Re: JScrollBar problems
- Index(es):
Relevant Pages
|
|