Example usage for java.awt GridBagLayout GridBagLayout

List of usage examples for java.awt GridBagLayout GridBagLayout

Introduction

In this page you can find the example usage for java.awt GridBagLayout GridBagLayout.

Prototype

public GridBagLayout() 

Source Link

Document

Creates a grid bag layout manager.

Usage

From source file:MouseEventDemo.java

public MouseEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;// ww w  . j  av  a2 s  .  c o m
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f));
    gridbag.setConstraints(blankArea, c);
    add(blankArea);

    c.insets = new Insets(0, 0, 0, 0);
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    //Register for mouse events on blankArea and the panel.
    blankArea.addMouseListener(this);
    addMouseListener(this);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:de.codesourcery.eve.skills.ui.components.impl.TotalItemValueComponent.java

@Override
protected JPanel createPanel() {
    textField.setColumns(10);//from  www  .  j  a va 2s .c o  m
    textField.setEditable(false);
    textField.setHorizontalAlignment(JTextField.TRAILING);

    JPanel textFieldPanel = new JPanel();
    textField.setLayout(new GridBagLayout());
    textFieldPanel.setBorder(BorderFactory.createTitledBorder(title));
    textFieldPanel.add(textField,
            constraints(0, 0).weightX(0.5).weightY(0.5).resizeHorizontally().useRelativeWidth());

    setISKAmountLabel(ISKAmount.ZERO_ISK);
    return textFieldPanel;
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanHistoryPanel.java

private void initializeComponent() {
    if (!this.initialized) {
        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        GridBagConstraints existingScansPanelConstraints = new GridBagConstraints();
        existingScansPanelConstraints.anchor = GridBagConstraints.WEST;
        existingScansPanelConstraints.fill = GridBagConstraints.BOTH;
        existingScansPanelConstraints.gridx = 0;
        existingScansPanelConstraints.gridy = 0;
        existingScansPanelConstraints.weightx = 1.0;
        existingScansPanelConstraints.weighty = 1.0;
        existingScansPanelConstraints.gridheight = 1;
        existingScansPanelConstraints.gridwidth = 1;
        existingScansPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.existingScansListPanel = new ListInputPanel<Scan>(this, this, true, true);
        this.add(this.existingScansListPanel, existingScansPanelConstraints);

        this.addAncestorListener(new AncestorListener() {
            public void ancestorAdded(AncestorEvent event) {
                applicationDelegate.addEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());

                applicationDelegate.loadScans();
            }//from w w  w  .ja  va  2s .com

            public void ancestorRemoved(AncestorEvent event) {
                applicationDelegate.removeEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScansLoadedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDeletedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorMoved(AncestorEvent event) {
            }
        });

        this.initialized = true;
    }
}

From source file:MultiListener.java

public MultiListener() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    JLabel l = null;/*from   www  .j  av  a2s.co m*/

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    l = new JLabel("What MultiListener hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    topTextArea = new JTextArea();
    topTextArea.setEditable(false);
    JScrollPane topScrollPane = new JScrollPane(topTextArea);
    Dimension preferredSize = new Dimension(200, 75);
    topScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(topScrollPane, c);
    add(topScrollPane);

    c.weightx = 0.0;
    c.weighty = 0.0;
    l = new JLabel("What Eavesdropper hears:");
    gridbag.setConstraints(l, c);
    add(l);

    c.weighty = 1.0;
    bottomTextArea = new JTextArea();
    bottomTextArea.setEditable(false);
    JScrollPane bottomScrollPane = new JScrollPane(bottomTextArea);
    bottomScrollPane.setPreferredSize(preferredSize);
    gridbag.setConstraints(bottomScrollPane, c);
    add(bottomScrollPane);

    c.weightx = 1.0;
    c.weighty = 0.0;
    c.gridwidth = 1;
    c.insets = new Insets(10, 10, 0, 10);
    button1 = new JButton("Blah blah blah");
    gridbag.setConstraints(button1, c);
    add(button1);

    c.gridwidth = GridBagConstraints.REMAINDER;
    button2 = new JButton("You don't say!");
    gridbag.setConstraints(button2, c);
    add(button2);

    button1.addActionListener(this);
    button2.addActionListener(this);

    button2.addActionListener(new Eavesdropper(bottomTextArea));

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));
}

From source file:Main.java

public Main() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    // Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    // Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//from ww  w . jav a 2s. co  m
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; // Fill entire cell.
    c.weighty = 1.0; // Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; // Add/remove buttons have equal width.
    c.gridwidth = 1; // NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; // Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

    setPreferredSize(new Dimension(400, 400));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:ChiSquareCalculator.java

ChiSquareCalculator() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);/* w  w  w. jav a  2  s. c o m*/
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.setResizable(false);

    // panel 1
    JPanel pn1 = new JPanel();
    pn1.setOpaque(true);
    pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2"));

    JLabel jlab1 = new JLabel("class 1");
    JLabel jlab2 = new JLabel("class 2");
    JLabel jlab3 = new JLabel("case");
    JLabel jlab4 = new JLabel("control");

    jtf1 = new JTextField();
    jtf2 = new JTextField();
    jtf3 = new JTextField();
    jtf4 = new JTextField();

    // pn1 layout all
    GridBagLayout CalLayout1 = new GridBagLayout();
    GridBagConstraints gbc1 = new GridBagConstraints();
    pn1.setLayout(CalLayout1);
    gbc1.weightx = 1.0; //default 0.0
    gbc1.weighty = 1.0; //default 0.0      
    gbc1.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc1.fill = GridBagConstraints.BOTH;

    gbc1.gridwidth = 1;

    gbc1.gridx = 1;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jlab3, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jlab4, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf3, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf4, gbc1);

    pn1.add(jlab1);
    pn1.add(jlab2);
    pn1.add(jlab3);
    pn1.add(jlab4);
    pn1.add(jtf1);
    pn1.add(jtf2);
    pn1.add(jtf3);
    pn1.add(jtf4);

    // panel 2
    JPanel pn2 = new JPanel();
    pn2.setOpaque(true);
    pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3"));

    JLabel jlab5 = new JLabel("class 1");
    JLabel jlab6 = new JLabel("class 2");
    JLabel jlab7 = new JLabel("class 3");
    JLabel jlab8 = new JLabel("case");
    JLabel jlab9 = new JLabel("control");

    jtf5 = new JTextField();
    jtf6 = new JTextField();
    jtf7 = new JTextField();
    jtf8 = new JTextField();
    jtf9 = new JTextField();
    jtf10 = new JTextField();

    // pn2 layout all
    GridBagLayout CalLayout2 = new GridBagLayout();
    GridBagConstraints gbc2 = new GridBagConstraints();
    pn2.setLayout(CalLayout2);
    gbc2.weightx = 1.0; //default 0.0
    gbc2.weighty = 1.0; //default 0.0      
    gbc2.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc2.fill = GridBagConstraints.BOTH;

    gbc2.gridwidth = 1;

    gbc2.gridx = 1;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jlab8, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jlab9, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf8, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf9, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf10, gbc2);

    pn2.add(jlab5);
    pn2.add(jlab6);
    pn2.add(jlab7);
    pn2.add(jlab8);
    pn2.add(jlab9);
    pn2.add(jtf5);
    pn2.add(jtf6);
    pn2.add(jtf7);
    pn2.add(jtf8);
    pn2.add(jtf9);
    pn2.add(jtf10);

    // panel 3      
    JPanel pn3 = new JPanel();
    pn3.setOpaque(true);
    pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic"));

    JLabel jlab10 = new JLabel("chi-square");
    JLabel jlab11 = new JLabel("degree of freedom");

    jtf11 = new JTextField();
    jtf12 = new JTextField();

    GridBagLayout CalLayout3 = new GridBagLayout();
    GridBagConstraints gbc3 = new GridBagConstraints();
    pn3.setLayout(CalLayout3);
    gbc3.weightx = 1.0; //default 0.0
    gbc3.weighty = 1.0; //default 0.0      
    gbc3.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc3.fill = GridBagConstraints.BOTH;

    gbc3.gridwidth = 1;

    gbc3.gridx = 0;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jlab10, gbc3);

    gbc3.gridwidth = 3;

    gbc3.gridx = 1;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jtf11, gbc3);

    gbc3.gridwidth = 2;

    gbc3.gridx = 0;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jlab11, gbc3);

    gbc3.gridx = 2;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jtf12, gbc3);

    pn3.add(jlab10);
    pn3.add(jlab11);
    pn3.add(jtf11);
    pn3.add(jtf12);

    JPanel pn4 = new JPanel();
    pn4.setOpaque(true);
    pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result"));

    JLabel jlab12 = new JLabel("p-value");
    final JLabel jlab13 = new JLabel("odds ratio");
    final JLabel jlab14 = new JLabel("standard error");
    final JLabel jlab15 = new JLabel("confidence interval 95%");

    jtf13 = new JTextField();
    jtf14 = new JTextField();
    jtf15 = new JTextField();
    jtf16 = new JTextField();
    jtf17 = new JTextField();

    jlab13.setEnabled(false);
    jlab14.setEnabled(false);
    jlab15.setEnabled(false);
    jtf14.setEnabled(false);
    jtf15.setEnabled(false);
    jtf16.setEnabled(false);
    jtf17.setEnabled(false);

    JButton jbtn1 = new JButton("Run 2x2");
    jbtn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4;
            try {
                number1 = Long.parseLong(jtf1.getText());
                number2 = Long.parseLong(jtf2.getText());
                number3 = Long.parseLong(jtf3.getText());
                number4 = Long.parseLong(jtf4.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][2];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[1][0] = number3;
            obs[1][1] = number4;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(1));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");

            jlab13.setEnabled(true);
            jlab14.setEnabled(true);
            jlab15.setEnabled(true);
            jtf14.setEnabled(true);
            jtf15.setEnabled(true);
            jtf16.setEnabled(true);
            jtf17.setEnabled(true);

            double or = (double) (number2 * number3) / (number1 * number4);
            double se = Math.sqrt(
                    (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4);
            double logOR = Math.log(or);
            double logU95 = logOR + 1.96 * se;
            double logL95 = logOR - 1.96 * se;
            double U95 = Math.exp(logU95);
            double L95 = Math.exp(logL95);

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.000000");

            jtf14.setText(String.valueOf(or));
            jtf15.setText(String.valueOf(se));
            jtf16.setText(String.valueOf(mydf.format(L95)));
            jtf17.setText(String.valueOf(mydf.format(U95)));

        }
    });

    JButton jbtn2 = new JButton("Run 2x3");
    jbtn2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4, number5, number6;
            try {
                number1 = Long.parseLong(jtf5.getText());
                number2 = Long.parseLong(jtf6.getText());
                number3 = Long.parseLong(jtf7.getText());
                number4 = Long.parseLong(jtf8.getText());
                number5 = Long.parseLong(jtf9.getText());
                number6 = Long.parseLong(jtf10.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][3];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[0][2] = number3;
            obs[1][0] = number4;
            obs[1][1] = number5;
            obs[1][2] = number6;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(2));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);

        }
    });

    JButton jbtn3 = new JButton("Run Statistic");
    jbtn3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            double stat, df;
            try {
                stat = Double.parseDouble(jtf11.getText());
                df = Double.parseDouble(jtf12.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!");
                return;
            }
            ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
            double pvalue = 1 - distribution.cumulativeProbability(stat);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    JButton jbtn4 = new JButton("clear");
    jbtn4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf11.setText("");
            jtf12.setText("");
            jtf13.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    GridBagLayout CalLayout4 = new GridBagLayout();
    GridBagConstraints gbc4 = new GridBagConstraints();
    pn4.setLayout(CalLayout4);
    gbc4.weightx = 1.0; //default 0.0
    gbc4.weighty = 1.0; //default 0.0      
    gbc4.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc4.fill = GridBagConstraints.BOTH;

    gbc4.gridwidth = 1;

    gbc4.gridx = 0;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn1, gbc4);

    gbc4.gridx = 1;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn2, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn3, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn4, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jlab12, gbc4);

    gbc4.gridwidth = 3;

    gbc4.gridx = 1;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jtf13, gbc4);

    gbc4.gridwidth = 2;

    gbc4.gridx = 0;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jlab13, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jtf14, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jlab14, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jtf15, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jlab15, gbc4);

    gbc4.gridwidth = 1;

    gbc4.gridx = 2;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf16, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf17, gbc4);

    pn4.add(jlab12);
    pn4.add(jlab13);
    pn4.add(jlab14);
    pn4.add(jlab15);
    pn4.add(jtf13);
    pn4.add(jtf14);
    pn4.add(jtf15);
    pn4.add(jtf16);
    pn4.add(jtf17);
    pn4.add(jbtn1);
    pn4.add(jbtn2);
    pn4.add(jbtn3);
    pn4.add(jbtn4);

    // jfrm layout all
    GridBagLayout CalLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    jfrm.setLayout(CalLayout);

    gbc.weightx = 1.0; //default 0.0
    gbc.weighty = 1.0; //default 0.0

    gbc.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 4;

    gbc.gridx = 0;
    gbc.gridy = 0;
    CalLayout.setConstraints(pn1, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    CalLayout.setConstraints(pn2, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    CalLayout.setConstraints(pn3, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    CalLayout.setConstraints(pn4, gbc);

    jfrm.add(pn1);
    jfrm.add(pn2);
    jfrm.add(pn3);
    jfrm.add(pn4);

    // Help Menu Bar
    JMenuBar jmb = new JMenuBar();
    JMenu jmh = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmiAbout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(jfrm,
                    "Name:          Chi Square Calculator\n" + "Version:       1.0\n"
                            + "Author:         Felix Yanhui Fan\n" + "EMail:           nolanfyh@gmail.com\n"
                            + "Website:     http://felixfan.github.io/ChiSquareCalculator\n");

        }
    });
    JMenuItem jmiLisence = new JMenuItem("Lisence");
    jmiLisence.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfrm,
                    "This program is licensed under the terms of \n"
                            + "the GNU General Public License version 3 \n" + "Available online under: \n"
                            + "http://www.gnu.org/licenses/gpl-3.0.html\n");

        }
    });

    jmh.add(jmiAbout);
    jmh.add(jmiLisence);

    jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar
    jmb.add(jmh);

    jfrm.setJMenuBar(jmb);

    jfrm.setVisible(true);
}

From source file:SwingMouseMotionEventDemo.java

public SwingMouseMotionEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.fill = GridBagConstraints.BOTH;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;/*w  ww . ja va 2s.  co  m*/
    c.weighty = 1.0;

    c.insets = new Insets(1, 1, 1, 1);
    blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f));
    gridbag.setConstraints(blankArea, c);
    add(blankArea);

    c.insets = new Insets(0, 0, 0, 0);
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    //Register for mouse events on blankArea and panel.
    blankArea.addMouseMotionListener(this);
    addMouseMotionListener(this);

    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:width.java

 public void init() {
     GridBagLayout gridBag = new GridBagLayout();
     GridBagConstraints c = new GridBagConstraints();

     setLayout(gridBag);/*from w w w .  j  a  va2s  .co  m*/

     Label receiverLabel = new Label("Receiver name:", 
                                     Label.RIGHT);
     gridBag.setConstraints(receiverLabel, c);
     add(receiverLabel);

     nameField = new TextField(getParameter("RECEIVERNAME"),
                                            10);
     c.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(nameField, c);
     add(nameField);
     nameField.addActionListener(this);

     Button button = new Button("Send message");
     c.gridwidth = GridBagConstraints.REMAINDER; //end row
     c.anchor = GridBagConstraints.WEST; //stick to the 
                                         //text field
     c.fill = GridBagConstraints.NONE; //keep the button 
                                       //small
     gridBag.setConstraints(button, c);
     add(button);
     button.addActionListener(this);

     status = new TextArea(5, 60);
     status.setEditable(false);
     c.anchor = GridBagConstraints.CENTER; //reset to the default
     c.fill = GridBagConstraints.BOTH; //make this big
     c.weightx = 1.0;
     c.weighty = 1.0;
     gridBag.setConstraints(status, c);
     add(status);

     myName = getParameter("NAME");
     Label senderLabel = new Label("(My name is " + myName + ".)",
                                   Label.CENTER);
     c.weightx = 0.0;
     c.weighty = 0.0;
     gridBag.setConstraints(senderLabel, c);
     add(senderLabel);

newline = System.getProperty("line.separator");
 }

From source file:com.stefanbrenner.droplet.ui.ActionPanel.java

/**
 * Create the panel./*w  ww  .  j  a  v  a 2 s  .  c  o  m*/
 */
public ActionPanel(final IActionDevice device, final T action) {

    setDevice(device);
    setAction(action);

    setLayout(new GridBagLayout());
    setBackground(DropletColors.getBackgroundColor(getDevice()));

    GridBagConstraints gbc = UiUtils.createGridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new Insets(2, 2, 2, 2);

    BeanAdapter<IAction> adapter = new BeanAdapter<IAction>(action, true);

    // enabled checkbox
    cbEnable = BasicComponentFactory.createCheckBox(adapter.getValueModel(IAction.PROPERTY_ENABLED),
            StringUtils.EMPTY);
    cbEnable.setToolTipText(Messages.getString("ActionPanel.enableAction.tooltip")); //$NON-NLS-1$
    cbEnable.setFocusable(false);
    UiUtils.editGridBagConstraints(gbc, 0, 0, 0, 0);
    add(cbEnable, gbc);

    // offset spinner
    spOffset = new MouseWheelSpinner(true);
    spOffset.setToolTipText(Messages.getString("ActionPanel.Offset.Tooltip")); //$NON-NLS-1$
    spOffset.setModel(SpinnerAdapterFactory.createNumberAdapter(adapter.getValueModel(IAction.PROPERTY_OFFSET),
            0, 0, ActionPanel.MAX_TIME_INPUT, 1));
    ((JSpinner.DefaultEditor) spOffset.getEditor()).getTextField().setColumns(4);
    UiUtils.editGridBagConstraints(gbc, 1, 0, 0, 0);
    add(spOffset, gbc);

    // duration spinner
    spDuration = new MouseWheelSpinner(true);
    spDuration.setToolTipText(Messages.getString("ActionPanel.Duration.Tooltip")); //$NON-NLS-1$
    if (action instanceof IDurationAction) {
        spDuration.setModel(SpinnerAdapterFactory.createNumberAdapter(
                adapter.getValueModel(IDurationAction.PROPERTY_DURATION), 0, 0, ActionPanel.MAX_TIME_INPUT, 1));
        ((JSpinner.DefaultEditor) spDuration.getEditor()).getTextField().setColumns(4);
        UiUtils.editGridBagConstraints(gbc, 2, 0, 0, 0);
        add(spDuration, gbc);
    }

    // remove button
    btnRemove = new JButton(Messages.getString("ActionPanel.removeAction")); //$NON-NLS-1$
    btnRemove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            remove();
        }
    });
    btnRemove.setToolTipText(Messages.getString("ActionPanel.removeAction.tooltip")); //$NON-NLS-1$
    btnRemove.setFocusable(false);
    UiUtils.editGridBagConstraints(gbc, 3, 0, 0, 0);
    add(btnRemove, gbc);

}

From source file:ContainerEventDemo.java

public ContainerEventDemo() {
    super(new GridBagLayout());
    GridBagLayout gridbag = (GridBagLayout) getLayout();
    GridBagConstraints c = new GridBagConstraints();

    // Initialize an empty list of buttons.
    buttonList = new Vector<JButton>(10, 10);

    // Create all the components.
    addButton = new JButton("Add a button");
    addButton.setActionCommand(ADD);//w  ww . j a  v  a 2s  .com
    addButton.addActionListener(this);

    removeButton = new JButton("Remove a button");
    removeButton.setActionCommand(REMOVE);
    removeButton.addActionListener(this);

    buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setPreferredSize(new Dimension(200, 75));
    buttonPanel.addContainerListener(this);

    display = new JTextArea();
    display.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(200, 75));

    clearButton = new JButton("Clear text area");
    clearButton.setActionCommand(CLEAR);
    clearButton.addActionListener(this);

    c.fill = GridBagConstraints.BOTH; // Fill entire cell.
    c.weighty = 1.0; // Button area and message area have equal height.
    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(scrollPane, c);
    add(scrollPane);

    c.weighty = 0.0;
    gridbag.setConstraints(clearButton, c);
    add(clearButton);

    c.weightx = 1.0; // Add/remove buttons have equal width.
    c.gridwidth = 1; // NOT end of row
    gridbag.setConstraints(addButton, c);
    add(addButton);

    c.gridwidth = GridBagConstraints.REMAINDER; // end of row
    gridbag.setConstraints(removeButton, c);
    add(removeButton);

    c.weighty = 1.0; // Button area and message area have equal height.
    gridbag.setConstraints(buttonPanel, c);
    add(buttonPanel);

    setPreferredSize(new Dimension(400, 400));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}