Problems With Scroll

I have this problem with JScroll where no matter how I change the sizes, the scroll bar doesn't show up or it doesn't scroll when panels are added to the main panel. Btw, the mainPanel adds other panels too it, and when the amount of panels gets out of bounds, its suppose to scroll the panels. Heres the code

AddWorkout(){

//Panels.Dialg and Scroll

screen=new JDialog();

mainPanel=new JPanel();

scroll=new JScrollPane(mainPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

//Objects

frame=new FrameChooser();

image=new ImageLoader();

chooserFrame=new JFrame();

//Screen size

dim = Toolkit.getDefaultToolkit().getScreenSize();

//Layouts

mainPanel.setLayout(null);

screen.setLayout(null);

//methods

frame.newObject(AddWorkout.this);

setDatePanel();

//Sizes

screen.setSize(600,dim.height-20);

mainPanel.setSize(600,dim.height-20);

scroll.setSize(600,dim.height-20);

mainPanel.setPreferredSize(new Dimension(300, 300));

scroll.setPreferredSize(new Dimension(300,300));

//Stuff that you need to worry About

frame.repButton.addActionListener(this);

frame.cooldownButton.addActionListener(this);

frame.stretchButton.addActionListener(this);

frame.warmupButton.addActionListener(this);

frame.longRunButton.addActionListener(this);

frame.fartlekButton.addActionListener(this);

chooserFrame.getContentPane().add(frame.options);

chooserFrame.setSize(500,200);

chooserFrame.setLocation(600,0);

chooserFrame.setVisible(true);

//Last Step

screen.setVisible(true);

screen.getContentPane().add(scroll);

}

Please Help

[2674 byte] By [blackmagea] at [2007-11-27 9:19:05]
# 1

Ok, part of the problem is fixed when I do this:

//Sizes

screen.setSize(600,dim.height-20);

//mainPanel.setSize(600,dim.height-20);

//scroll.setSize(600,dim.height-20);

mainPanel.setPreferredSize(new Dimension(300, 300));

//scroll.setPreferredSize(new Dimension(300,300));

I changed a few things around in my program and now all the panels added to the mainPanel appear. The scrollbar appears but now the problem is when it reaches out of the screens size, it doesn't add to the scroll to see the other panels being added. Any solutons?

Message was edited by:

blackmage

blackmagea at 2007-7-12 22:10:57 > top of Java-index,Desktop,Core GUI APIs...
# 2

If you use a "null" layout manager, then you are responsible for setting the preferred size of your panel. Thats why we recommend you use a Layout Manager.

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",

see http://homepage1.nifty.com/algafield/sscce.html,

that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the "Code Formatting Tags",

see http://forum.java.sun.com/help.jspa?sec=formatting,

so the posted code retains its original formatting.

camickra at 2007-7-12 22:10:57 > top of Java-index,Desktop,Core GUI APIs...