File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Scrolling a JPanel

Casen Densmore

Joined: Jan 22, 2004
Posts: 14

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?

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Nageswar Kakolla
Ranch Hand

Joined: Jan 16, 2006
Posts: 71

JScrollPane scrollPane = new JScrollPane();

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
I agree. Here's the link:
subject: Scrolling a JPanel
It's not a secret anymore!