File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes GridBagLayout question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GridBagLayout question" Watch "GridBagLayout question" New topic
Author

GridBagLayout question

Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
Hi all,

I was trying my hands on using GridBagLayout to lay down my components.
Can anyone tell me... how to place a button and textfields with some constant width and height using this layout, so that even if the window is maximised, they stay to be of the same size.


i am trying to create this sort of structure
basically a form.
---------------------------------------------------
Label 1 TEXTFIELD
BUTTON
label 2 TEXTFIELD
---------------------------------------------------

Regards
Akhil


-------------------------------<br />you can't move ahead, unless you try for it.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Akhil Jain
Ranch Hand

Joined: Oct 14, 2004
Posts: 74
hi craig,

thanks for that code....can you tell me what i am doing wrong here....



structure which i am looking for to create with above code is this:--->



i want this structure to remain as it is...even when i maximize the window.I am simply not able to do this.i have drawn this image using Absolute Layout.........but i dont want to use Absolute anymore....how can i do the same thing using GridBagLayout....can you help me out with this.?

[ November 09, 2007: Message edited by: Akhil Jain ]
[ November 09, 2007: Message edited by: Akhil Jain ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Your layout image shows the layout centered instead of alligned to the west/left. To
center this layout change all the anchor constraints form LINE_START to CENTER.
Use the insets constraints to alter the spacing among components.
Managing the weightx constraint is how we keep the components all aligned to the left. The
weightx values for all components should be zero except for the last component in each
row.

Edit:
Your layout image shows the layout centered instead of alligned to the west/left. To
center this layout change all the anchor constraints form LINE_START to CENTER.

And set all weightx constraints to zero.
[ November 09, 2007: Message edited by: Craig Wood ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GridBagLayout question
 
Similar Threads
Layout Managers & Proper Spacing
. . .not abstract and doesnt overide abstract method actionPerfomed
So difficult to use Layout managers!!!
GridBagLayout HELP
method not abstract