• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting components in GridBagLayout

 
Jos� Alberto Mu�iz Navarro
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I wrote a simple JFrame that would display three components using the GridBagLayout. However, I have two problems:
* Even though I have a setSize(300, 300), the Frame that appears is really small (like 10 x 10 px). I have to resize it manually to see the components
* If I type anything in the TextAreas, they grow in size. Is there any way to prevent this from happening?
The code is here:

THANK YOU ! I appreciate your help.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the setSize and setVisible calls to the end of the constructor because then they will have the info required to do the layout and you will get a properly sized frame.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And use JTextArea constructors that allow you to set the character width and height as well as set the initial text. You can also call setLineWrap(boolean wrap).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!