• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFrame not sizing

 
shilpa reddy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I am having trouble with a JFrame.
I have added 2 panels containing some textfields onto the frame.
I have not set the size of the panels.
I have not set the size for the frame but have specified pack() in the frame constructor.My understanding is that it should fit the components i.e the textfields
When I run the app the frame appears minimized.
Why doesn't it take the size of the components.
Thanks in advance.
Shilpa
 
Golam Newaz
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
did you use getContentPane() like this
getContentPane().setLayout(new BorderLayout());
Look in Combobox JFrame and other codes come in this way:
JFrame
|
Content Pane
|
JPanel
|
JLabel, etc.
Example:
JPanel p=new JPanel();
getContentPane().add(p);
Also use this statement into your constructor:
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
// other code....
setResizable(false);
pack();
setVisible(true);
I think it should solve your problem,
Thanks,
Golam Sayeed Newaz
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!