aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Scrolling a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scrolling a JPanel" Watch "Scrolling a JPanel" New topic
Author

Scrolling a JPanel

Casen Densmore
Greenhorn

Joined: Jan 22, 2004
Posts: 14
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

Joined: Jun 09, 2003
Posts: 4632
scrollPane.getVerticalScrollBar().setValue(0);
Nageswar Kakolla
Ranch Hand

Joined: Jan 16, 2006
Posts: 71
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
 
Don't get me started about those stupid light bulbs.
 
subject: Scrolling a JPanel