Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dynamically limit the size of a JFrame

Status
Not open for further replies.

rdoor

Technical User
May 4, 2002
43
US
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);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top