Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to adjust sizes and positions in a JPanel/JFrame  RSS feed

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a good Swing programmer so I'm having frustrations on to what to do with this:



I couldn't fix the positions and the sizes... Can you help me convert this frame into something normal (normal sizes for text fields and buttons).

Here's my code:


Thank you very much in advance!
[ October 16, 2008: Message edited by: Denise Saulon ]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A GridLayout will size all of its components equally, and you can't change that. Since in the end all your panels have the same number of components, they end up all the same size.

I'd suggest forgetting about GridLayout for this, and use a combination of other layout managers. I think that with BorderLayout and GroupLayout you should be able to get quite far.
 
Pavan Kumar Srinivasan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 3 ways to make the gui layout look better .

1)GridBagLayout(Part of the standard jdk) --> GridBag Tutorial

2)MigLayout --> (Great Layout Manager ...even better than GridBagLayout but outside the jdk package)

3)Netbans Mattise GUI Builder --> Download from netbeans.org (this is the easiest way using Drag N Drop to create quick protottypes)

[ October 16, 2008: Message edited by: Pavan Kumar Srinivasan ]
[ October 16, 2008: Message edited by: Pavan Kumar Srinivasan ]
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pavan Kumar Srinivasan:
1)GridBagLayout(Part of the standard jdk) --> GridBag Tutorial

Totally Gridbag.

I'd rather shoot myself in the foot than ever use GridBagLayout.

MigLayout and JGoodies Forms' FormsLayout are also quite good but not part of the core API.
 
Pavan Kumar Srinivasan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I perfectly understand that gridbaglayout is very hard to learn ....but once you get a hang of it...you can achieve alomost any layout.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pavan Kumar Srinivasan:
There are 3 ways to make the gui layout look better .

1)GridBagLayout(Part of the standard jdk) --> GridBag Tutorial...


Go ahead and create a GridBagLayout example here and I'll at least match you with standard but non-GridBag layout code.
 
Suraj Chandran
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd rather shoot myself in the foot than ever use GridBagLayout.


I agree with Rob. Though GBL is flexible, its a real pain in the back. MigLayout is cool. MigLayout seems cool.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!