Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Sophia Green
Ranch Hand
Posts: 30
  • 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: 2703
10
  • 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: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob Camick Thanks a lot!:-)
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!