DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   need help in gridBagLayout (http://www.daniweb.com/forums/thread127469.html)

C41R0 Jun 3rd, 2008 8:03 am
need help in gridBagLayout
 
1 Attachment(s)
.
.
.
.

 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

Ezzaral Jun 3rd, 2008 2:17 pm
Re: need help in gridBagLayout
 
After you create the "mainPane", you need to set it's layout to GridBagLayout like so
mainPane.setLayout(new GridBagLayout());

C41R0 Jun 4th, 2008 8:41 am
Re: need help in gridBagLayout
 
thanks a lot, Ezzaral, you have help me out from this problem, what a careless mistake i've made


All times are GMT -4. The time now is 3:40 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC