• 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

GridBagLayout Problem

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a tabbed pane. In one of it's tabs I have a panel with the GridBagLayout as the layout manager. Now when I am adding a Label and a textbox pair then they are added in the center of the panel. I want the Label and the textbox pair to get added from the top of the panel. How can I do that?
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anirban dutta:
I am having a tabbed pane. In one of it's tabs I have a panel with the GridBagLayout as the layout manager. Now when I am adding a Label and a textbox pair then they are added in the center of the panel. I want the Label and the textbox pair to get added from the top of the panel. How can I do that?



While adding components to the panel, use GridBagConstaints
Eg:
panel.add(btnHello,GridBagConstaints.NORTHEAST)
for more info
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/GridBagConstraints.html
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Murthy,
I have done that but it doesen't work.

jPanel1 is the main panel in which all the components are added.
Please tell me where I am going wrong.
Thanks
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to add jPanel1.setLayout(new GridBagLayour); first since JPanel's default layout is FlowLayout
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add jpanel1 to another JPanel with a BorderLayout. Like this:

Kyle
 
reply
    Bookmark Topic Watch Topic
  • New Topic