views:

33

answers:

1

I am trying to initialize a JScrollPane to start life at the bottom. I do not want it to scroll automatically after it is initially shown. The scroll pane does not contain a subclass of JTextComponent, but rather a JPanel(GridLayout(0, 1)) containing many JPanels.

I tried using JViewport.scrollRectToVisible() inside an event handler on the parent Window (addComponentListener:componentShown), but it did not seem to work.

Any ideas?

+1  A: 

The scroll pane does not contain a subclass of JTextComponent, but rather a JPanel(GridLayout(0, 1)) containing many JPanels.

Then you need to scroll the panel:

panel.scrollRectToVisible(...);

Or you should be able to use:

JScrollBar sb = scrollPane.getVerticalScrollBar();
sb.setValue( sb.getMaximu() );

Also, this code needs to be executed "after" the GUI is visible.

camickr
+1 I think it can be after `pack()` and before `setVisible()`.
trashgod
Yes, it can be done after a pack().
camickr