need help in gridBagLayout

Thread Solved

Join Date: Feb 2008
Posts: 31
Reputation: C41R0 is an unknown quantity at this point 
Solved Threads: 0
C41R0 C41R0 is offline Offline
Light Poster

need help in gridBagLayout

 
0
  #1
Jun 3rd, 2008
  1. .
  2. .
  3. .
  4. .
  5.  
  6. button1.setIcon(pic1);
  7. button1.setToolTipText("Open File");
  8. toolBar.add(button1);
  9.  
  10. button2.setIcon(pic2);
  11. button2.setToolTipText("Save File");
  12. toolBar.add(button2);
  13.  
  14. button3.setIcon(pic3);
  15. button3.setToolTipText("Help File");
  16. toolBar.add(button3);
  17.  
  18. gbc1 = new GridBagConstraints();
  19. // c.insets = new Insets(2, 2, 2, 2);;
  20. gbc1.weighty = 1.0;
  21. gbc1.weightx = 1.0;
  22. gbc1.gridx = 0;
  23. gbc1.gridy = 0;
  24. // gbc.weightx = 30.0;
  25. // gbc.weighty = 30.0;
  26. // c.gridheight = 0;
  27.  
  28. gbc1.anchor = GridBagConstraints.NORTHWEST ;
  29. // gbl.setConstraints(toolBar, c);
  30.  
  31. contentPane.add(toolBar,gbc1);
  32. .
  33. .
  34. .
  35. .
  36. /* @@@@@@@@@@@@@@@@ creating panels @@@@@@@@@@@@@@@@ */
  37. JLabel locationLabel;
  38. JLabel divingTypeLabel;
  39. JLabel diveLogLabel;
  40. JLabel EquipmentLabel;
  41. JLabel fBuddyLabel;
  42. JLabel sBuddyLabel;
  43.  
  44. JLabel firstNameLabel;
  45. JPanel mainPane = new JPanel();
  46. JPanel diverPane = new JPanel();
  47. JTabbedPane tabs = new JTabbedPane();
  48. mainPane.setBorder(new LineBorder(Color.black, 5));
  49. Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
  50. Border borderTitle = BorderFactory.createTitledBorder(loweredetched, "Detail");
  51.  
  52.  
  53. locationLabel=new JLabel("Location: ");
  54. JTextField l = new JTextField(15);
  55. JTextField a = new JTextField(15);
  56. l.setBorder(BorderFactory.createEtchedBorder());
  57. // c.fill = GridBagConstraints.BOTH;
  58. gbc2 = new GridBagConstraints();
  59. gbc2.gridx = 0;
  60. gbc2.gridy = 0;
  61. mainPane.add(locationLabel,gbc2);
  62. gbc2.gridx = 1;
  63. gbc2.gridy = 0;
  64. mainPane.add(l, gbc2);
  65.  
  66. divingTypeLabel=new JLabel("Diving Type: ");
  67. a.setBorder(BorderFactory.createEtchedBorder());
  68. gbc2.gridx=0;
  69. gbc2.gridy=1;
  70. mainPane.add(divingTypeLabel, gbc2);
  71. gbc2.gridx=1;
  72. gbc2.gridy=1;
  73. mainPane.add(a, gbc2);
  74.  
  75.  
  76. gbc1.gridx = 0;
  77. gbc1.gridy = 1;
  78. // c.fill = GridBagConstraints.HORIZONTAL;
  79. // gbc.anchor = GridBagConstraints.NORTHWEST;
  80. gbc1.gridwidth = 2;
  81. // c.anchor = GridBagConstraints.WEST;
  82. gbc1.weightx = 30.0;
  83. gbc1.weighty = 30.0;
  84. gbc1.gridwidth = GridBagConstraints.REMAINDER;
  85. mainPane.setBorder(borderTitle);
  86. tabs.addTab(" Main ", mainPane);
  87. tabs.addTab(" Diver ", diverPane);
  88. contentPane.add(tabs,gbc1);


my component seem not in correct position, how to place my Diving Type and its JTextField underneath the "location" ? The picture that i've uploaded is the result of this code
Attached Thumbnails
untitled.JPG  
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 509
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: need help in gridBagLayout

 
0
  #2
Jun 3rd, 2008
After you create the "mainPane", you need to set it's layout to GridBagLayout like so
  1. mainPane.setLayout(new GridBagLayout());
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 31
Reputation: C41R0 is an unknown quantity at this point 
Solved Threads: 0
C41R0 C41R0 is offline Offline
Light Poster

Re: need help in gridBagLayout

 
0
  #3
Jun 4th, 2008
thanks a lot, Ezzaral, you have help me out from this problem, what a careless mistake i've made
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC