• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel is automatically resized

 
Roberto De Giuli
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BorderLayout lays out components based on their preferred size so try setting the preferred size of the panel.
 
Roberto De Giuli
Greenhorn
Posts: 17
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic