This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
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

Setting components in GridBagLayout  RSS feed

 
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!