I'm trying to make a variable size JFrame, depending on the number of components in it. The component in it is a scrollpane and in the scrollpane is a variable number of JPanels. I'd like to limit the size of the JFrame to 550 pixels, but I can't seem to get it done. It limits itself to 612 pixels, at which time the scrollpane is activated. Unfortunately, this is the full screen (I'm on a laptop with 600x800 screen) and the bottom of the scrollpane is hidden under the taskbar. How do I limit the size to 550?
Code is:
public class SomeClass extends JFrame{
. . .
public void viewAssessment(LinkedList visibleNodes, String student){
JScrollPane jsp = new JScrollPane();
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel jp = new JPanel();
GridLayout gl = new GridLayout(visibleNodes.size(),0);
gl.setVgap(-8);
jp.setLayout(gl);
Iterator it = visibleNodes.iterator();
while (it.hasNext()){ //this populates the JFrame with a variable number of JPanels
SANode san = (SANode)it.next();
jp.add(san.getStdPanel().showStdPanel());
}
jsp.setViewportView(jp);
getContentPane().add(jsp);
setLocation(200,0);
setVisible(true);
pack();
}
public Dimension getMaximumSize(){
return new Dimension(600,550);
}
Code is:
public class SomeClass extends JFrame{
. . .
public void viewAssessment(LinkedList visibleNodes, String student){
JScrollPane jsp = new JScrollPane();
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel jp = new JPanel();
GridLayout gl = new GridLayout(visibleNodes.size(),0);
gl.setVgap(-8);
jp.setLayout(gl);
Iterator it = visibleNodes.iterator();
while (it.hasNext()){ //this populates the JFrame with a variable number of JPanels
SANode san = (SANode)it.next();
jp.add(san.getStdPanel().showStdPanel());
}
jsp.setViewportView(jp);
getContentPane().add(jsp);
setLocation(200,0);
setVisible(true);
pack();
}
public Dimension getMaximumSize(){
return new Dimension(600,550);
}