Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Panel in ScrollPane

 
paul wheaton
Trailboss
Pie
Posts: 21378
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can add the panel to a scrollpane
than on to the container directly.
 
paul wheaton
Trailboss
Pie
Posts: 21378
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took my panel and converted it to a canvas-like thing and now it seems to work.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21378
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tried this under IE, but the following code works fine for me using JDK 1.2.2 for Windows:
 
Jesper Ottosson
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic