0 Replies Latest reply: Aug 18, 2013 5:28 PM by 1012252 RSS

    Java Applet - GridBagConstraint

    1012252

      Hi,

       

      I have a question, could somebody tell me how to decrease the space between buttons in my applet as g.weighty = 1; is making the gap too big? I would like to have all button on top with some space but the space I am getting now is too big and I can't find a way how to decrease it.

       

      import java.awt.*;
      import javax.swing.*;
      
      
      public class GUI extends JApplet{
      
        private GridBagConstraints g = new GridBagConstraints();
        private JPanel jPanelContentPanel;
        private JPanel jPanelButtonPanel;
        private JPanel jPanelGraphPanel;
        private JButton jButton1;
        private JButton jButton2;
        private JButton jButton3;
        private JButton jButton4;
        private GridBagLayout gridbag;
           
          public ApplicationGUI() {
            init();
          }
      
          public void init() {
      
        setSize(450,350);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        jPanelContentPanel = (JPanel) this.getContentPane();
      
        gridbag = new GridBagLayout();
      
      
        jPanelGraphPanel = new JPanel();
        jPanelGraphPanel.setBorder(BorderFactory.createTitledBorder(""));
        jPanelContentPanel.add(jPanelGraphPanel,BorderLayout.CENTER);
         
        jPanelButtonPanel = new JPanel(gridbag);
        jPanelButtonPanel.setBorder(BorderFactory.createTitledBorder(""));
        g.insets = new Insets(5,5,0,5);
        g.anchor = GridBagConstraints.PAGE_START;
        g.weighty = 1;
      
      
        jButton1  = new JButton("Button 1");
        jButton1.setPreferredSize(new Dimension(100, 30));
        g.gridx = 0;
        g.gridy = 0;
        jPanelButtonPanel.add(jButton1,g);
      
        jButton2 = new JButton("Button 2");
        jButton2.setPreferredSize(new Dimension(100, 30));
        g.gridx = 0;
        g.gridy = 1;
        jPanelButtonPanel.add(jButton2,g);
      
        jButton3 = new JButton("Button 3");
        jButton3.setPreferredSize(new Dimension(100, 30));
        g.gridx = 0;
        g.gridy = 2;
        jPanelButtonPanel.add(jButton3,g);
      
        jButton4 = new JButton("Button 4");
        jButton4.setPreferredSize(new Dimension(100, 30));
        g.gridx = 0;
        g.gridy = 3;
        jPanelButtonPanel.add(jButton4,g);
      
        jPanelContentPanel.add(jPanelButtonPanel,BorderLayout.EAST);
      
      
        }
      }
      
      
      

       

      Thank in advance