jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes Panel in ScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Panel in ScrollPane" Watch "Panel in ScrollPane" New topic
Author

Panel in ScrollPane

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20538
    ∞

I made a lovely panel that is rather large. I want to put it in a ScrollPane, but no dice.
What's wrong? Do I need to somehow attach it to a canvas or something?

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
you can add the panel to a scrollpane
than on to the container directly.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20538
    ∞

I took my panel and converted it to a canvas-like thing and now it seems to work.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have the same problem with big panel putting into a scrollpane. It doesn't work (at least with me) as other componets (like textarea) works with scrollpane. Is there any way of doing this?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20538
    ∞

I know that ScrollPane doesn't work right under IE. I ended up making my own scrolling object.
Also, a panel won't show up unless you specify its size.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I haven't tried this under IE, but the following code works fine for me using JDK 1.2.2 for Windows:


"I'm not back." - Bill Harding, Twister
Jesper Ottosson
Ranch Hand

Joined: Mar 21, 2000
Posts: 51
i had a similiar proplem recently. i was putting a large JPanel inside a JScrollPane, and the adding the scrollpane to another JPanel. When the window was too small the scrollbars were showing, i think, but they weren't visible, because the outmost jpanel was too small (since it wasnt in a scrollpane)
It took me some time to figure out what was wrong... so i hope this is helping
// Jesper
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Jim,
Your following code works fine -
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame {
public Test() {
JLabel bigLabel = new JLabel("Really Big Label");
JLabel.getFont().deriveFont(200.0F));
JPanel panel = new JPanel();
panel.add(bigLabel);
JScrollPane scrollPane = new JScrollPane(panel);
getContentPane().add(scrollPane);
setSize(new Dimension(200, 200));
setVisible(true);
}

public static void main(String[] s) {
new Test();
}
}
What about if you add the following line in the code:
panel.setLayout(null);
No more scrollpanel when I add that line in my program.
Any idea?
(but it works when you set other type of layout)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Panel in ScrollPane