Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scrolling a JPanel

 
Casen Densmore
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am having trouble with scrolling a JPanel. When it displays the JPanel it is scrolled all the way to the bottom and I can't seem to find a method where I can force the initial location of the "knob" on the Scrollbar.

Here is how I implement the JPanel


I am using a GridBagLayout for the JPanel where I place some buttons and text. Right now I am doing an uber-ugly hack where I place a empty JTextArea at the very top of the JPanel and set the caret position to 0 on that component, but what is the reason it is scrolling all the way to the bottom?

Thanks,
Casen
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scrollPane.getVerticalScrollBar().setValue(0);
 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

JScrollPane scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.getViewport().add(m_itemPanel);


Obviously, My problem is adding JScrollPane(Scrollable bar) to JPanel.
JPanel has set of Radio Buttons with 3 in each line. I want to have Scrollable Pane visible and whenever buttons exceed the size of window, I can scroll down.

Help will be appreciated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic