• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help in gridbaglayout

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are happy with Group, why not stick with Group?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
adeeb alexander
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic