| | |
need help in gridBagLayout
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 31
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
. . . . button1.setIcon(pic1); button1.setToolTipText("Open File"); toolBar.add(button1); button2.setIcon(pic2); button2.setToolTipText("Save File"); toolBar.add(button2); button3.setIcon(pic3); button3.setToolTipText("Help File"); toolBar.add(button3); gbc1 = new GridBagConstraints(); // c.insets = new Insets(2, 2, 2, 2);; gbc1.weighty = 1.0; gbc1.weightx = 1.0; gbc1.gridx = 0; gbc1.gridy = 0; // gbc.weightx = 30.0; // gbc.weighty = 30.0; // c.gridheight = 0; gbc1.anchor = GridBagConstraints.NORTHWEST ; // gbl.setConstraints(toolBar, c); contentPane.add(toolBar,gbc1); . . . . /* @@@@@@@@@@@@@@@@ creating panels @@@@@@@@@@@@@@@@ */ JLabel locationLabel; JLabel divingTypeLabel; JLabel diveLogLabel; JLabel EquipmentLabel; JLabel fBuddyLabel; JLabel sBuddyLabel; JLabel firstNameLabel; JPanel mainPane = new JPanel(); JPanel diverPane = new JPanel(); JTabbedPane tabs = new JTabbedPane(); mainPane.setBorder(new LineBorder(Color.black, 5)); Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); Border borderTitle = BorderFactory.createTitledBorder(loweredetched, "Detail"); locationLabel=new JLabel("Location: "); JTextField l = new JTextField(15); JTextField a = new JTextField(15); l.setBorder(BorderFactory.createEtchedBorder()); // c.fill = GridBagConstraints.BOTH; gbc2 = new GridBagConstraints(); gbc2.gridx = 0; gbc2.gridy = 0; mainPane.add(locationLabel,gbc2); gbc2.gridx = 1; gbc2.gridy = 0; mainPane.add(l, gbc2); divingTypeLabel=new JLabel("Diving Type: "); a.setBorder(BorderFactory.createEtchedBorder()); gbc2.gridx=0; gbc2.gridy=1; mainPane.add(divingTypeLabel, gbc2); gbc2.gridx=1; gbc2.gridy=1; mainPane.add(a, gbc2); gbc1.gridx = 0; gbc1.gridy = 1; // c.fill = GridBagConstraints.HORIZONTAL; // gbc.anchor = GridBagConstraints.NORTHWEST; gbc1.gridwidth = 2; // c.anchor = GridBagConstraints.WEST; gbc1.weightx = 30.0; gbc1.weighty = 30.0; gbc1.gridwidth = GridBagConstraints.REMAINDER; mainPane.setBorder(borderTitle); tabs.addTab(" Main ", mainPane); tabs.addTab(" Diver ", diverPane); 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
After you create the "mainPane", you need to set it's layout to GridBagLayout like so
Java Syntax (Toggle Plain Text)
mainPane.setLayout(new GridBagLayout());
![]() |
Similar Threads
- GridBagLayout HELP (Java)
- GridBag layout problems. (Java)
- How to position buttons/boxes in a JTabbed Pane? (Java)
- I Need Help Please! (Java)
- "cannot resolve symbol"problem (Java)
- Set Size for JSlider (Java)
- Creating a GUI that accepts user input help (Java)
- Choice of layout. (Java)
- URGENT Help Needed With TicTacToe Application Source Code!!! (Java)
- Help with program...Please...... (Java)
Other Threads in the Java Forum
- Previous Thread: Java Random Access File... Help
- Next Thread: read a column of text from a file in java
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working






