This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 2173
    
  47
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: 2173
    
  47
My pleasure
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel is automatically resized
 
Similar Threads
jframe problem
Drawing with mouse
list of component not displayed
Setting frame to the correct size
BackgroundPanel.java cannot be placed in BorderLayout.NORTH