File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPanel is automatically resized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel is automatically resized" Watch "JPanel is automatically resized" New topic
Author

JPanel is automatically resized

Roberto De Giuli
Greenhorn

Joined: Feb 01, 2013
Posts: 17

Hello.
I've been writing a simple swing application. The main JFrame window has a BorderLayout:



I've added a JPanel to my top level JFrame container:



where "pannelloBtn" is my JPanel.
The JPanel code for "pannelloBtn" is located in a custom class that extends JPanel. In the constructor I've added the following code:



Now I have a problem: when I run the application the JPanel's width is resized to zero, even if I've specified a minimun width of 400.
I can't solve it: any help is more than welcome. Thank you very much!

Roberto
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2398
    
  50
BorderLayout lays out components based on their preferred size so try setting the preferred size of the panel.
Roberto De Giuli
Greenhorn

Joined: Feb 01, 2013
Posts: 17

Tony Docherty wrote:BorderLayout lays out components based on their preferred size so try setting the preferred size of the panel.


Thank you very much, now it works!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2398
    
  50
My pleasure
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel is automatically resized