aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Help in gridbaglayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help in gridbaglayout" Watch "Help in gridbaglayout" New topic
Author

Help in gridbaglayout

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi all
The code below doesnt do what it has to do. I need to place the components on the top left of my panel. But the components be still in the center of panel after giving this also gbc.anchor=GridBagConstraints.NORTHWEST; It doent work until i set gbc.weightx=0.0; and gbc.weighty=0.0;. Here the components get at the top position but the gap in between them is increasing. Someone please help me out. The code is here.

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
I'm not sure myself, but it looks like the following document addresses your issue, about 3/4 of the way down the page.

http://java.sun.com/developer/onlineTraining/GUI/AWTLayoutMgr/shortcourse.html
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi.
Can any one please suggest me to use which layout. I really want to know that which layout is good. I am good in GroupLayouts. Now please suggest me that that sahll i continue with grouplayout or change to other layout.


Thanks and Regards
alexander
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
often a good layout manager is a combination of different layout managers to achieve the desired effect. In that sense, I would say it is difficult to recommend a specific layout for your situation.

The article is very good at describing how to use a combination of different Layout Managers to achieve the desired result.

Try to break your GUI into high level sections, whereby you can describe the layout of these sections relative to each other using a known manager. Then, you can describe the layout within each section by using it's own layout manager. Sort of a nesting of simple layout managers to achieve a more complex end result.

If you could show a picture of your desired layout, it would be easier to advise of specific layout managers to use.

p.s edited for clarity
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38389
    
  23
if you are happy with Group, why not stick with Group?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi Craig
Thanks for your example i am able to got little bit into my head and added a label and textfield now the problem is that they are getting placed in the center. When i increase the weigtx and weighty i am able to place in the correct position but i have observed that the value is needed to be increased by 50 and for other row again i have to add more two zeros that is 5000 then only i am getting the components in correct position. Please execute the code if you can. Then you can get my problem. The code is here.

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks a lot guyz i have learn t lot about the GridBagLayout. No i have got a simple doubt in the code below. When i arrange the components in the following order
l1 t1 l2 t2
l3 t3
l4 t4

its ok. i can arrange them, but when i reduce the size of t1 i.e t3 is 25 and t1 is 10 then gap between t1 and l2 is increased that is l2 and t2 remains at there old place only. How can i move them closer.


Thanks and Regards
alexander
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The components in each row are laid out in columns and their size determines the width of the columns. One way to work with this is to use a separate panel (to bridge across columns) for/in a row.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in gridbaglayout