Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a button in GridBagLayout is making the JLabels and JTextArea shrink  RSS feed

 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have this form for which I used GridBagLayout. When I added a button in the end, the labels have kind of disappeared.

Here is my code:




Main

Screenshot-(249).png
[Thumbnail for Screenshot-(249).png]
This is how it looks after adding the Book Room button
Screenshot-(250).png
[Thumbnail for Screenshot-(250).png]
Here is how it looks before adding the button
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Don't use the setSize() method. If a component can't be displayed at its preferred size it will be displayed at its minimum size, which for a text field is 0.

Use frame.pack() so every component can be displayed at its preferred size.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob Camick Thanks a lot!:-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!