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

GridBagLayout Problem  RSS feed

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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?
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Anthony Yip
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to add jPanel1.setLayout(new GridBagLayour); first since JPanel's default layout is FlowLayout
 
kyle amburn
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add jpanel1 to another JPanel with a BorderLayout. Like this:

Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!