Example usage for java.awt Container setLayout

List of usage examples for java.awt Container setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:op.care.med.inventory.DlgTX.java

/**
 * This method is called from within the constructor to
 * initialize the form./*from w  w w .  j a v a  2  s. c o m*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the PrinterForm Editor.
 */
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
    lblText = new JLabel();
    txtText = new JTextField();
    txtValue = new JTextField();
    lblValue = new JLabel();
    lblUnit = new JLabel();
    lblWeightControl = new JLabel();
    txtWeightControlled = new JTextField();
    lblUnit2 = new JLabel();
    panel1 = new JPanel();
    btnCancel = new JButton();
    btnBuchung = new JButton();

    //======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(
            new FormLayout("default, $lcgap, default, $ugap, 141dlu:grow, $rgap, default, $lcgap, default",
                    "2*(default, $lgap), fill:default, $lgap, default, $lgap, fill:default"));

    //---- lblText ----
    lblText.setText("Buchungstext");
    lblText.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblText, CC.xy(3, 3, CC.DEFAULT, CC.TOP));

    //---- txtText ----
    txtText.setColumns(100);
    txtText.addActionListener(e -> txtTextActionPerformed(e));
    contentPane.add(txtText, CC.xywh(5, 3, 3, 1));

    //---- txtValue ----
    txtValue.setHorizontalAlignment(SwingConstants.RIGHT);
    txtValue.setText("jTextField1");
    txtValue.setFont(new Font("Arial", Font.PLAIN, 14));
    txtValue.addCaretListener(e -> txtMengeCaretUpdate(e));
    txtValue.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtMengeFocusGained(e);
        }
    });
    txtValue.addActionListener(e -> txtValueActionPerformed(e));
    contentPane.add(txtValue, CC.xy(5, 5));

    //---- lblValue ----
    lblValue.setText("Menge");
    lblValue.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblValue, CC.xy(3, 5));

    //---- lblUnit ----
    lblUnit.setHorizontalAlignment(SwingConstants.TRAILING);
    lblUnit.setText("jLabel4");
    lblUnit.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblUnit, CC.xy(7, 5));

    //---- lblWeightControl ----
    lblWeightControl.setText("Menge");
    lblWeightControl.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblWeightControl, CC.xy(3, 7));

    //---- txtWeightControlled ----
    txtWeightControlled.setHorizontalAlignment(SwingConstants.RIGHT);
    txtWeightControlled.setText("jTextField1");
    txtWeightControlled.setFont(new Font("Arial", Font.PLAIN, 14));
    txtWeightControlled.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtWeightControlledFocusGained(e);
        }
    });
    txtWeightControlled.addCaretListener(e -> txtWeightControlledCaretUpdate(e));
    contentPane.add(txtWeightControlled, CC.xy(5, 7));

    //---- lblUnit2 ----
    lblUnit2.setHorizontalAlignment(SwingConstants.TRAILING);
    lblUnit2.setText("g");
    lblUnit2.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblUnit2, CC.xy(7, 7, CC.LEFT, CC.DEFAULT));

    //======== panel1 ========
    {
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));

        //---- btnCancel ----
        btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png")));
        btnCancel.addActionListener(e -> btnCancelActionPerformed(e));
        panel1.add(btnCancel);

        //---- btnBuchung ----
        btnBuchung.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png")));
        btnBuchung.addActionListener(e -> btnBuchungActionPerformed(e));
        panel1.add(btnBuchung);
    }
    contentPane.add(panel1, CC.xywh(5, 9, 3, 1, CC.RIGHT, CC.DEFAULT));
    setSize(600, 165);
    setLocationRelativeTo(getOwner());
}

From source file:pcgen.gui2.dialog.CharacterHPDialog.java

private void initComponents() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    JTable table = new JTable(tableModel) {

        @Override/* w  w  w. j  a va  2 s  .c o  m*/
        public TableCellEditor getCellEditor(int row, int column) {
            if (column == 5) {//TODO: the max roll should be calculated in a different manner
                String hd = levels.getClassTaken(levels.getElementAt(row)).getHD();
                int max = NumberUtils.toInt(hd);
                return new IntegerEditor(1, max);
            } else {
                return super.getCellEditor(row, column);
            }
        }

    };
    table.setDefaultRenderer(JButton.class, new Renderer());
    table.setDefaultEditor(JButton.class, new Editor());
    table.setCellSelectionEnabled(false);
    table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height);
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);

    JScrollPane scrollPane = new JScrollPane(table);
    pane.add(scrollPane, BorderLayout.CENTER);

    Box box = Box.createHorizontalBox();
    box.add(new JLabel("Total Hp:"));
    box.add(Box.createHorizontalStrut(3));

    final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() {

        @Override
        public void referenceChanged(ReferenceEvent<Integer> e) {
            totalHp.setText(e.getNewReference().toString());
        }

    };
    ReferenceFacade<Integer> hpRef = character.getTotalHPRef();
    totalHp.setText(hpRef.get().toString());
    hpRef.addReferenceListener(hpListener);
    box.add(totalHp);
    box.add(Box.createHorizontalStrut(5));

    JButton button = new JButton("Reroll All");
    button.setActionCommand("Reroll");
    button.addActionListener(this);
    box.add(button);

    box.add(Box.createHorizontalGlue());
    button = new JButton("Close");
    button.setActionCommand("Close");
    button.addActionListener(this);
    box.add(button);
    pane.add(box, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //Make sure to remove the listeners so that the garbage collector can
            //dispose of this dialog and prevent a memory leak
            levels.removeHitPointListener(tableModel);
            character.getTotalHPRef().removeReferenceListener(hpListener);
        }

    });

    Utility.installEscapeCloseOperation(this);
}

From source file:op.system.DlgLogin.java

/**
 * This method is called from within the constructor to
 * initialize the printerForm./*from  ww w .  j a v  a  2 s  .co m*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the PrinterForm Editor.
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    jPanel2 = new JPanel();
    lblOPDE = new JLabel();
    btnAbout = new JButton();
    lblUsernamePassword = new JLabel();
    txtUsername = new JTextField();
    txtPassword = new JPasswordField();
    panel1 = new JPanel();
    btnExit = new JButton();
    hSpacer1 = new JPanel(null);
    btnLogin = new JButton();

    //======== this ========
    setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    setResizable(false);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowActivated(WindowEvent e) {
            thisWindowActivated(e);
        }
    });
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout("13dlu, default, 13dlu",
            "13dlu, $lgap, fill:48dlu:grow, $lgap, default, $lgap, 13dlu"));

    //======== jPanel2 ========
    {
        jPanel2.setBorder(new EmptyBorder(5, 5, 5, 5));
        jPanel2.setOpaque(false);
        jPanel2.setLayout(new VerticalLayout(10));

        //---- lblOPDE ----
        lblOPDE.setText("Offene-Pflege.de");
        lblOPDE.setFont(new Font("Arial", Font.PLAIN, 24));
        lblOPDE.setHorizontalAlignment(SwingConstants.CENTER);
        jPanel2.add(lblOPDE);

        //---- btnAbout ----
        btnAbout.setIcon(new ImageIcon(getClass().getResource("/artwork/256x256/opde-logo.png")));
        btnAbout.setBorderPainted(false);
        btnAbout.setBorder(null);
        btnAbout.setOpaque(false);
        btnAbout.setContentAreaFilled(false);
        btnAbout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        btnAbout.setToolTipText(null);
        btnAbout.addActionListener(e -> btnAboutActionPerformed(e));
        jPanel2.add(btnAbout);

        //---- lblUsernamePassword ----
        lblUsernamePassword.setText("text");
        lblUsernamePassword.setFont(new Font("Arial", Font.PLAIN, 18));
        jPanel2.add(lblUsernamePassword);

        //---- txtUsername ----
        txtUsername.setFont(new Font("Arial", Font.PLAIN, 18));
        txtUsername.addActionListener(e -> txtUsernameActionPerformed(e));
        txtUsername.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                txtUsernameFocusGained(e);
            }
        });
        jPanel2.add(txtUsername);

        //---- txtPassword ----
        txtPassword.setFont(new Font("Arial", Font.PLAIN, 18));
        txtPassword.addActionListener(e -> txtPasswordActionPerformed(e));
        txtPassword.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                txtPasswordFocusGained(e);
            }
        });
        jPanel2.add(txtPassword);
    }
    contentPane.add(jPanel2, CC.xy(2, 3, CC.FILL, CC.DEFAULT));

    //======== panel1 ========
    {
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));

        //---- btnExit ----
        btnExit.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/exit.png")));
        btnExit.addActionListener(e -> btnExitActionPerformed(e));
        panel1.add(btnExit);
        panel1.add(hSpacer1);

        //---- btnLogin ----
        btnLogin.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png")));
        btnLogin.setActionCommand("btnLogin");
        btnLogin.addActionListener(e -> DoLogin(e));
        panel1.add(btnLogin);
    }
    contentPane.add(panel1, CC.xy(2, 5, CC.RIGHT, CC.DEFAULT));
    setSize(320, 540);
    setLocationRelativeTo(getOwner());
}

From source file:org.nyu.edu.dlts.CodeViewerDialog.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner non-commercial license
    dialogPane = new JPanel();
    contentPanel = new JPanel();
    scrollPane1 = new JScrollPane();
    messageTextArea = new JTextArea();
    buttonBar = new JPanel();
    recordTestPanel = new JPanel();
    openButton = new JButton();
    saveButton = new JButton();
    updateButton = new JButton();
    evaluateButton = new JButton();
    okButton = new JButton();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setTitle("Code Viewer");
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    //======== dialogPane ========
    {/*from w  w w .j a v a  2s . c o  m*/
        dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
        dialogPane.setLayout(new BorderLayout());

        //======== contentPanel ========
        {
            contentPanel.setLayout(new BorderLayout());

            //======== scrollPane1 ========
            {

                //---- messageTextArea ----
                messageTextArea.setRows(6);
                messageTextArea.setEditable(false);
                scrollPane1.setViewportView(messageTextArea);
            }
            contentPanel.add(scrollPane1, BorderLayout.SOUTH);
        }
        dialogPane.add(contentPanel, BorderLayout.CENTER);

        //======== buttonBar ========
        {
            buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
            buttonBar.setLayout(new GridBagLayout());
            ((GridBagLayout) buttonBar.getLayout()).columnWidths = new int[] { 0, 80 };
            ((GridBagLayout) buttonBar.getLayout()).columnWeights = new double[] { 1.0, 0.0 };

            //======== recordTestPanel ========
            {
                recordTestPanel.setLayout(new FormLayout(
                        new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
                                new ColumnSpec(ColumnSpec.FILL, Sizes.DEFAULT, FormSpec.DEFAULT_GROW),
                                FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC },
                        RowSpec.decodeSpecs("default")));

                //---- openButton ----
                openButton.setText("Open");
                openButton.setEnabled(false);
                recordTestPanel.add(openButton, cc.xy(1, 1));

                //---- saveButton ----
                saveButton.setText("Save");
                saveButton.setEnabled(false);
                recordTestPanel.add(saveButton, cc.xy(3, 1));

                //---- updateButton ----
                updateButton.setText("Update");
                updateButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        updateButtonActionPerformed();
                    }
                });
                recordTestPanel.add(updateButton, cc.xy(5, 1));

                //---- evaluateButton ----
                evaluateButton.setText("Evaluate Syntax");
                evaluateButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        evaluateButtonActionPerformed();
                    }
                });
                recordTestPanel.add(evaluateButton, cc.xy(9, 1));
            }
            buttonBar.add(recordTestPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));

            //---- okButton ----
            okButton.setText("Close");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    okButtonActionPerformed();
                }
            });
            buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
        dialogPane.add(buttonBar, BorderLayout.SOUTH);
    }
    contentPane.add(dialogPane, BorderLayout.CENTER);
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:wef.articulab.view.ui.CombinedBNXYPlot.java

/**
 * Creates a new demo instance./* www  . ja  va 2  s . c o m*/
 */
public CombinedBNXYPlot(String name1, String name2, String title1, String title2, String[] series1,
        String[] series2, boolean shouldPlot) {
    super("Social Reasoner");
    Container content = getContentPane();
    content.setLayout(new GridBagLayout());
    JPanel chartCSPanel = null;
    JPanel chartPhasePanel = null;

    if (shouldPlot) {
        chartContainer1 = new ChartContainer(name1, title1, series1);
        chartCSPanel = createChartPanel(chartContainer1);
        if (name2 != null) {
            chartContainer2 = new ChartContainer(name2, title2, series2);
            chartPhasePanel = createChartPanel(chartContainer2);
        } else {
            chartCSPanel.setPreferredSize(new Dimension(970, 750));
        }
    }
    inputPanel = createInputPanel();
    outputPanel = createOutputPanel();

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    add(outputPanel, gbc);
    add(Box.createRigidArea(new Dimension(0, 40)));

    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    add(inputPanel, gbc);

    if (shouldPlot) {
        if (chartPhasePanel != null) {
            gbc = new GridBagConstraints();
            gbc.gridx = 1;
            gbc.gridy = 0;
            add(chartCSPanel, gbc);

            gbc = new GridBagConstraints();
            gbc.gridx = 1;
            gbc.gridy = 1;
            add(chartPhasePanel, gbc);
        } else {
            gbc = new GridBagConstraints();
            gbc.gridx = 1;
            gbc.gridy = 0;
            gbc.gridheight = 2;
            add(chartCSPanel, gbc);
        }
    }

    pack();
    setVisible(true);
    setResizable(false);
}

From source file:edu.oregonstate.eecs.mcplan.domains.frogger.FroggerVisualization.java

public FroggerVisualization(final FroggerSimulator sim, final FroggerParameters params, final int scale) {
    if (sim != null) {
        this.sim = sim;
        this.state = sim.state();
    }/* ww  w . java2s.c  o  m*/

    this.scale = scale;

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                final JFrame frame = new JFrame();
                final Container cp = frame.getContentPane();
                cp.setLayout(new BorderLayout());

                draw_panel_ = new DrawPanel(params);
                final Dimension d = new Dimension(scale * params.road_length + 20,
                        scale * (params.lanes + 2) + 20);
                draw_panel_.setPreferredSize(d);
                draw_panel_.setSize(d);
                cp.add(draw_panel_, BorderLayout.CENTER);

                control_panel_ = new ControlPanel();
                cp.add(control_panel_, BorderLayout.SOUTH);

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setResizable(false);
                frame.pack();
                frame.setVisible(true);
            }
        });
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }

    if (sim != null) {
        updateStateOnEDT(sim.state());
    }
}

From source file:op.care.med.structure.DlgProduct.java

/**
 * This method is called from within the constructor to
 * initialize the form./*  www .  j a  va2s. com*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the PrinterForm Editor.
 */
// <editor-fold defaultstate="collapsed" desc=" Erzeugter Quelltext ">//GEN-BEGIN:initComponents
private void initComponents() {
    lblProductName = new JLabel();
    txtName = new JTextField();
    cmbAcme = new JComboBox<>();
    lblAcme = new JLabel();
    btnAdd = new JButton();
    lblSideEffects = new JLabel();
    scrollPane1 = new JScrollPane();
    txtSideEffects = new JTextArea();
    panel1 = new JPanel();
    btnCancel = new JButton();
    btnOK = new JButton();

    //======== this ========
    setModal(true);
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout("2*(default, $lcgap), default:grow, 2*($lcgap, default)",
            "default, 2*($lgap, fill:default), $lgap, fill:default:grow, $lgap, fill:default, $lgap, default"));

    //---- lblProductName ----
    lblProductName.setText("Produktname");
    lblProductName.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblProductName, CC.xy(3, 3));

    //---- txtName ----
    txtName.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(txtName, CC.xywh(5, 3, 3, 1));

    //---- cmbAcme ----
    cmbAcme.setModel(
            new DefaultComboBoxModel<>(new String[] { "Eintrag 1", "Eintrag 2", "Eintrag 3", "Eintrag 4" }));
    cmbAcme.setFont(new Font("Arial", Font.PLAIN, 14));
    cmbAcme.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            cmbAcmeItemStateChanged(e);
        }
    });
    contentPane.add(cmbAcme, CC.xy(5, 5));

    //---- lblAcme ----
    lblAcme.setText("Hersteller");
    lblAcme.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblAcme, CC.xy(3, 5));

    //---- btnAdd ----
    btnAdd.setText(null);
    btnAdd.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png")));
    btnAdd.setContentAreaFilled(false);
    btnAdd.setBorder(null);
    btnAdd.setSelectedIcon(new ImageIcon(getClass().getResource("/artwork/22x22/bw/add-pressed.png")));
    btnAdd.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    btnAdd.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnAddActionPerformed(e);
        }
    });
    contentPane.add(btnAdd, CC.xy(7, 5, CC.LEFT, CC.DEFAULT));

    //---- lblSideEffects ----
    lblSideEffects.setText("Hersteller");
    lblSideEffects.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(lblSideEffects, CC.xy(3, 7, CC.DEFAULT, CC.TOP));

    //======== scrollPane1 ========
    {

        //---- txtSideEffects ----
        txtSideEffects.setFont(new Font("Arial", Font.PLAIN, 14));
        scrollPane1.setViewportView(txtSideEffects);
    }
    contentPane.add(scrollPane1, CC.xywh(5, 7, 3, 1));

    //======== panel1 ========
    {
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));

        //---- btnCancel ----
        btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/16x16/cancel.png")));
        btnCancel.setText(null);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnCancelActionPerformed(e);
            }
        });
        panel1.add(btnCancel);

        //---- btnOK ----
        btnOK.setIcon(new ImageIcon(getClass().getResource("/artwork/16x16/apply.png")));
        btnOK.setText(null);
        btnOK.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnOKActionPerformed(e);
            }
        });
        panel1.add(btnOK);
    }
    contentPane.add(panel1, CC.xywh(5, 9, 3, 1, CC.RIGHT, CC.DEFAULT));
    setSize(585, 285);
    setLocationRelativeTo(null);
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Adds a component to a container, using the specified gridbag-layout and
 * the supplied parameters. <br>// www .j  a  v  a  2  s  .c  o  m
 * <br>
 * This method is simply used to ged rid of thousands of lines of code,
 * which inevitably rise when layouts such as the gridbag-layout is being
 * used.
 *
 * @param layout
 *            The layout to be used.
 * @param container
 *            The {@link Container}, to which the component will be added.
 * @param component
 *            An AWT {@link Component}, that will be added to the container.
 * @param fill
 *            A constant describing the fill behaviour (see
 *            {@link GridBagConstraints}). Can be <code>null</code>, if no
 *            filling wants to be specified.
 * @param anchor
 *            A constant describing the anchor of the element in its parent
 *            container (see {@link GridBagConstraints}). Can be
 *            <code>null</code>, if no specification is needed.
 * @param gridX
 *            The relative grid-X coordinate.
 * @param gridY
 *            The relative grid-Y coordinate.
 * @param width
 *            The relative width of the component.
 * @param height
 *            The relative height of the component.
 * @param weightX
 *            A value for the horizontal weight.
 * @param weightY
 *            A value for the vertical weight.
 * @param insets
 *            Insets of the component. Can be <code>null</code>.
 */
private static void addComponent(GridBagLayout layout, Container container, Component component, Integer fill,
        Integer anchor, Insets insets, int gridX, int gridY, int width, int height, double weightX,
        double weightY, int ipadX, int ipadY) {
    container.setLayout(layout);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = gridX;
    constraints.gridy = gridY;
    constraints.gridwidth = width;
    constraints.gridheight = height;
    constraints.weightx = weightX;
    constraints.weighty = weightY;
    constraints.ipadx = ipadX;
    constraints.ipady = ipadY;
    if (fill != null) {
        constraints.fill = fill;
    }
    if (insets != null) {
        constraints.insets = insets;
    }
    if (anchor != null) {
        constraints.anchor = anchor;
    }
    layout.setConstraints(component, constraints);
    container.add(component);
}

From source file:main.java.gui.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - BOHDAN Korinnyi
    test = new JFrame();
    label1 = new JLabel();
    textField1 = new JTextField();
    label2 = new JLabel();
    textField2 = new JTextField();
    label3 = new JLabel();
    label4 = new JLabel();
    textField3 = new JTextField();
    textField4 = new JTextField();
    button1 = new JButton();
    button2 = new JButton();
    label5 = new JLabel();
    label6 = new JLabel();

    //======== test ========
    {// www  .  j a  v  a  2s.c  o m
        test.setTitle("Pay mobile account");
        Container testContentPane = test.getContentPane();
        testContentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u0421\u0443\u043c\u0430");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 4f));
        testContentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(35, 30), label1.getPreferredSize()));

        //---- textField1 ----
        textField1.setColumns(10);
        testContentPane.add(textField1);
        textField1.setBounds(150, 30, 105, textField1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u041d\u043e\u043c\u0435\u0440");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 4f));
        testContentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(35, 60), label2.getPreferredSize()));

        //---- textField2 ----
        textField2.setText("0674060606");
        textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 2f));
        testContentPane.add(textField2);
        textField2.setBounds(150, 60, 105, textField2.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u041b\u043e\u0433\u0456\u043d");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 4f));
        testContentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(35, 95), label3.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u041f\u0430\u0440\u043e\u043b\u044c");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 4f));
        testContentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(35, 125), label4.getPreferredSize()));
        testContentPane.add(textField3);
        textField3.setBounds(150, 95, 105, textField3.getPreferredSize().height);
        testContentPane.add(textField4);
        textField4.setBounds(150, 125, 105, 20);

        //---- button1 ----
        button1.setText("\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u0438");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD,
                button1.getFont().getSize() + 2f));
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strTemp = textField1.getText();
                int cash = Integer.parseInt(strTemp);
                if (cash < 1) {
                    JOptionPane.showMessageDialog(null, "    '", "",
                            JOptionPane.OK_OPTION);
                    textField1.setText("0");
                } else if (textField3.getText().equals("test4") && textField4.getText().equals("12345")) {
                    check c = new check();
                    pay p = new pay();
                    getstatus g = new getstatus();
                    try {
                        c.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        p.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        information i = new information();
                        daoImplements h = new daoImplements();
                        long curTime = System.currentTimeMillis();
                        String curStringDate = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(curTime);

                        i.setIdTransaction(getTransaction.setGetTransaction());
                        i.setData(curStringDate);
                        i.setNumber(Integer.parseInt(getNumber()));
                        i.setSuma(Integer.parseInt(getMoney()));
                        i.setStatus(parserStatus.getStatusParsing());
                        h.addInfo(i);

                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (ParseException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "    ", "",
                            JOptionPane.OK_OPTION);
                    System.exit(0);
                }
            }

        });
        testContentPane.add(button1);
        button1.setBounds(150, 155, 115, 25);

        //---- button2 ----
        button2.setText("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getStyle() | Font.BOLD,
                button2.getFont().getSize() + 2f));
        button2.setActionCommand("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tableData t = new tableData();
            }
        });
        testContentPane.add(button2);
        button2.setBounds(15, 155, 115, 25);

        //---- label5 ----
        label5.setText(
                "\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0441\u0435\u0440\u0432\u0456\u0441 \u043f\u043e\u043f\u043e\u0432\u043d\u0435\u043d\u043d\u044f \u043c\u043e\u0431\u0456\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0445\u0443\u043d\u043a\u0443");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getStyle() & ~Font.ITALIC));
        testContentPane.add(label5);
        label5.setBounds(15, 0, 255, 20);

        //---- label6 ----
        label6.setText("38");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 4f));
        testContentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(130, 60), label6.getPreferredSize()));

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < testContentPane.getComponentCount(); i++) {
                Rectangle bounds = testContentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = testContentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            testContentPane.setMinimumSize(preferredSize);
            testContentPane.setPreferredSize(preferredSize);
        }
        test.pack();
        test.setLocationRelativeTo(test.getOwner());
    }
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:edu.oregonstate.eecs.mcplan.domains.sailing.SailingVisualization.java

public SailingVisualization(final SailingFsssModel sim, final int scale) {
    if (sim != null) {
        this.sim = sim;
        this.state = sim.initialState();
    }/*from w w  w.j  a va 2s.  c  om*/

    this.scale = scale;
    final SailingTerrain[][] circuit = state.terrain;

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                frame = new JFrame();
                final Container cp = frame.getContentPane();
                cp.setLayout(new BorderLayout());

                draw_panel_ = new DrawPanel(circuit);
                final Dimension d = new Dimension(scale * circuit[0].length + 20, scale * circuit.length + 20);
                draw_panel_.setPreferredSize(d);
                draw_panel_.setSize(d);
                cp.add(draw_panel_, BorderLayout.CENTER);

                control_panel_ = new ControlPanel();
                cp.add(control_panel_, BorderLayout.SOUTH);

                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setResizable(false);
                frame.pack();
                frame.setVisible(true);
            }
        });
    } catch (final Exception ex) {
        throw new RuntimeException(ex);
    }

    if (sim != null) {
        updateStateOnEDT(state);
    }
}