• Post Reply Bookmark Topic Watch Topic
  • New Topic

ScrollPane to top - that old chesnut...

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I've had a look through pretty much every posting and can't get my scroll pane to scroll back to the top after I've added my panel. This is what I've tried:
--------------------------
pnlChoices - contains a long list of panels
JViewport oView = new JViewport();
oView.add(pnlChoices);
scollPane.setViewport(oView);
pnlChoices.setLocation(new Point(0, 0));
scollPane.getViewport().setViewPosition(new Point(0, 0));
// This is the first panel contained in pnlChoices
if (pnlFirstChoice != null)
{
pnlFirstChoice.requestFocus();
}
scollPane.getViewport().scrollRectToVisible(new Rectangle(new Point(0, 0)));
JScrollBar bar = scollPane.getVerticalScrollBar();
bar.setValue(bar.getMinimum());
--------------------------------
I've tried pretty much every combination of the above as well. (I've created the view port separately as I also tried making the calls directly to the view port object instead of using the getViewport() method).
Any help would be GREATLY appreciated as I have spent about 10 hours on this now and I'm beginning to lose the will to live...
Cheers,
Steve
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not the viewport, but the component inside the viewport should be the one you call scrollRectToVisible() on...

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, thank you, thank you .
Cheers,
Steve
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add a bit more, when I removed the button, the above code still didn't work for me.
To correct the problem, I put the button event into the window openned event and that did the trick. Not sure if it's great technique, but it works and after many days wasted, I'm happy.
Thanks again,
Steve
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!