Example usage for java.awt GridBagConstraints CENTER

List of usage examples for java.awt GridBagConstraints CENTER

Introduction

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

Prototype

int CENTER

To view the source code for java.awt GridBagConstraints CENTER.

Click Source Link

Document

Put the component in the center of its display area.

Usage

From source file:MainClass.java

public MainClass() {
    super("Clipboard Test");
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    setLayout(gridbag);// w ww  . j a  va  2 s.  co m

    srcText = new TextArea(8, 32);
    c.gridwidth = 2;
    c.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(srcText, c);
    add(srcText);

    copyButton = new Button("Copy Above");
    copyButton.setActionCommand("copy");
    copyButton.addActionListener(this);
    c.gridy = 1;
    c.gridwidth = 1;
    gridbag.setConstraints(copyButton, c);
    add(copyButton);

    pasteButton = new Button("Paste Below");
    pasteButton.setActionCommand("paste");
    pasteButton.addActionListener(this);
    pasteButton.setEnabled(false);
    c.gridx = 1;
    gridbag.setConstraints(pasteButton, c);
    add(pasteButton);

    dstText = new TextArea(8, 32);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 2;
    gridbag.setConstraints(dstText, c);
    add(dstText);

    pack();
}

From source file:Main.java

public static void addComponent(Container container, GridBagLayout gbl, Component c, int x, int y, int width,
        int height, int fill) {
    addComponent(container, gbl, c, x, y, width, height, 1, 1, GridBagConstraints.CENTER, 0, 0, fill);

}

From source file:Main.java

public MyPanel() {
    JTextField labelA = new JTextField("Your A component");
    JTextField labelB = new JTextField("Your B component");
    JTextField labelC = new JTextField("Your C component");
    JTextField labelD = new JTextField("Top Right D");

    JPanel north = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.FIRST_LINE_END;
    gbc.weightx = 1;/*from  www  .  ja v a2s  . c  o  m*/
    gbc.insets = new Insets(10, 10, 10, 10);
    north.add(labelD, gbc);

    JPanel south = new JPanel(new GridBagLayout());
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridy = 0;
    south.add(labelA, gbc);
    gbc.gridy = 1;
    south.add(labelB, gbc);
    gbc.gridy = 2;
    south.add(labelC, gbc);

    setLayout(new BorderLayout());
    add(north, BorderLayout.NORTH);
    add(south, BorderLayout.CENTER);
}

From source file:Main.java

protected void addFields(GridBagConstraints gbc) {
    JTextField field1 = new JTextField("0", 5);
    field1.setEnabled(false);/*from w  w w  .ja va2s  .co m*/
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.gridx++;
    add(field1, gbc);
    gbc.gridx++;
    gbc.insets = new Insets(0, 4, 0, 4);
    add(new JLabel("+"), gbc);
    JTextField field2 = new JTextField(5);
    gbc.gridx++;
    add(field2, gbc);
}

From source file:pipeline.parameter_cell_views.CurveEditor.java

public CurveEditor() {
    super();//w ww  . j av  a 2s.  c om

    setPreferredSize(new Dimension(500, 500));

    setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.CENTER;
    c.gridheight = 2;

    parameterName = new JLabel("");
    splineEditor = new SplineDisplay();

    splineEditor.addPropertyChangeListener(evt -> {
        currentParameter
                .setValue(new Object[] { splineEditor.getCurvePoints(), splineEditor.getControlPoints() });
        boolean saveSilenceUpdate = silenceUpdate;
        silenceUpdate = true;
        currentParameter.fireValueChanged(false, true, true);// The parameter value might still be
        // changing, but the information is not passed up from the SplineDisplay
        silenceUpdate = saveSilenceUpdate;
    });

    c.gridx = 0;
    c.gridy = 0;
    c.weighty = 1.0;
    c.weightx = 1.0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    add(splineEditor, c);
    c.gridwidth = 1;
    c.ipady = 0;
    parameterName = new JLabel("parameter");
    c.gridx = 0;
    c.gridy = 1;
    c.weighty = 0.01;
    c.weightx = 0.0;
    parameterName.setMaximumSize(new Dimension(10000, 30));
    add(parameterName, c);
}

From source file:com.github.pemapmodder.pocketminegui.gui.server.ConsolePanel.java

public ConsolePanel(ServerMainActivity activity) {
    this.activity = activity;
    setLayout(new GridBagLayout());
    setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 10));
    title = new JLabel("PocketMine-MP");
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.CENTER;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weighty = 0.1;/*ww  w. j av a2s . com*/
    add(title, c);
    stdout = new JEditorPane();
    stdout.setContentType("text/html");
    stdout.setText("<html><body style='font-family: monospace; color: #FFFFFF;'><p id='p'></p></body></html>");
    doc = (HTMLDocument) stdout.getDocument();
    para = doc.getElement("p");
    //      stdout.setEditable(false);
    // People NEED to see this to feel happy
    stdout.setForeground(Color.WHITE);
    stdout.setBackground(Color.BLACK);
    Style style = doc.getStyleSheet().addStyle(null, null);
    //      style.addAttribute(StyleConstants.Foreground, Color.WHITE);
    //      style.addAttribute(StyleConstants.Background, Color.RED);
    doc.setParagraphAttributes(para.getStartOffset(), 1, style, true);
    stdout.setBorder(BorderFactory.createDashedBorder(new Color(0x80, 0x80, 0x80)));
    c.gridy = 1;
    c.weightx = 0.9;
    c.weighty = 0.9;
    c.weighty = 0.6;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTH;
    add(stdout, c);
    Timer timer = new Timer(50, e -> updateConsole());
    timer.start();
}

From source file:org.mbs3.juniuploader.gui.pnlUploadSites.java

private void initGUI() {
    try {//  w w  w.  ja va  2  s .c om
        GridBagLayout thisLayout = new GridBagLayout();
        this.setLayout(thisLayout);
        {
            btnAddSite = new JButton();
            this.add(btnAddSite, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            btnAddSite.setText("Add Site to List");
            btnAddSite.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnAddSiteActionPerformed(evt);
                }
            });
        }
        {
            btnRemoveSite = new JButton();
            this.add(btnRemoveSite, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            btnRemoveSite.setText("Remove Selected Site");
            btnRemoveSite.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnRemoveSiteActionPerformed(evt);
                }
            });
        }
        {
            jScrollPane1 = new JScrollPane();
            this.add(jScrollPane1, new GridBagConstraints(1, 1, 1, 4, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            jScrollPane1.setPreferredSize(new java.awt.Dimension(367, 362));
            {
                lstUploadSites = new JList();
                jScrollPane1.setViewportView(lstUploadSites);
                lstUploadSites.setModel(frmMain.uploadLocations);
                lstUploadSites.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
            }
        }
        thisLayout.rowWeights = new double[] { 0.0, 0.1, 0.1, 0.0, 0.1, 0.0 };
        thisLayout.rowHeights = new int[] { 9, 20, 7, 8, 7, 9 };
        thisLayout.columnWeights = new double[] { 0.0, 0.1, 0.0, 0.0, 0.0 };
        thisLayout.columnWidths = new int[] { 11, 20, 9, 217, 11 };
        this.setPreferredSize(new java.awt.Dimension(614, 382));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.mbs3.juniuploader.gui.pnlAbout.java

private void initGUI() {
    try {/*from  ww w.ja v a 2  s . c o m*/
        GridBagLayout thisLayout = new GridBagLayout();
        thisLayout.rowWeights = new double[] { 0.0, 0.0, 0.1, 0.0, 0.0, 0.1, 0.0 };
        thisLayout.rowHeights = new int[] { 7, 25, 20, 8, 23, 20, 6 };
        thisLayout.columnWeights = new double[] { 0.0, 0.1, 0.1 };
        thisLayout.columnWidths = new int[] { 11, 7, 20 };
        this.setLayout(thisLayout);
        this.setPreferredSize(new java.awt.Dimension(626, 368));
        {
            lblImage1 = new JLabel();
            File fImage = new File("logo1.gif");
            if (fImage != null & fImage.canRead()) {
                ImageIcon i = new ImageIcon(fImage.getAbsolutePath());
                lblImage1.setIcon(i);
            }
            this.add(lblImage1, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
        {
            lblLogo1Desc = new JLabel();
            this.add(getLblLogo1Desc(), new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            lblLogo1Desc.setText("Logo2:");
        }
        {
            jLabel1 = new JLabel();
            this.add(jLabel1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            jLabel1.setText("Logo1:");
        }
        {
            lblImage2 = new JLabel();
            File fImage2 = new File("logo2.gif");
            if (fImage2 != null & fImage2.canRead()) {
                ImageIcon i = new ImageIcon(fImage2.getAbsolutePath());
                lblImage2.setIcon(i);
            }

            this.add(lblImage2, new GridBagConstraints(1, 5, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
    } catch (Exception ex) {
        log.error("initGui() exception", ex);
    }
}

From source file:org.altusmetrum.altosuilib_2.AltosUIEnable.java

public void add(String name, AltosUIGrapher grapher, boolean enabled) {

    GraphElement e = new GraphElement(name, grapher, enabled);
    GridBagConstraints c = new GridBagConstraints();

    /* Add element */
    c = new GridBagConstraints();
    c.gridx = x;/*  w  ww .j a v  a  2  s  .  c  o m*/
    c.gridy = y;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = ir;
    add(e.enable, c);

    /* Next row */
    y++;
    if (y == max_rows) {
        x++;
        y = 0;
    }
}

From source file:org.mbs3.juniuploader.gui.pnlFormVariables.java

private void initGUI() {
    try {/*  www  . j  a  v a 2 s.  c o m*/
        GridBagLayout thisLayout = new GridBagLayout();
        this.setLayout(thisLayout);
        {
            btnAddPair = new JButton();
            this.add(btnAddPair, new GridBagConstraints(3, 3, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            btnAddPair.setText("Add a New Pair");
            btnAddPair.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnAddPairActionPerformed(evt);
                }
            });
        }
        {
            btnRemPair = new JButton();
            this.add(btnRemPair, new GridBagConstraints(3, 6, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            btnRemPair.setText("Remove Selected Pair");
            btnRemPair.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnRemPairActionPerformed(evt);
                }
            });
        }
        {

            cmbFormGroups = new JComboBox();
            this.add(cmbFormGroups, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            cmbFormGroups.setModel(frmMain.formGroups);
            cmbFormGroups.addItemListener(new ItemListener() {
                public void itemStateChanged(ItemEvent evt) {
                    cmbFormGroupsItemStateChanged(evt);
                }
            });
        }
        {

            DefaultComboBoxModel groups = frmMain.formGroups;
            FormPairGroup fpg = (FormPairGroup) groups.getSelectedItem();
            DefaultComboBoxModel dcbmFormPairs;
            if (fpg != null)
                dcbmFormPairs = new DefaultComboBoxModel(fpg.getPairs());
            else
                dcbmFormPairs = new DefaultComboBoxModel();

            lstFormPairValues = new JList();
            lstFormPairValues.setModel(dcbmFormPairs);

            this.add(lstFormPairValues, new GridBagConstraints(1, 3, 1, 4, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
            lstFormPairValues.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        }

        {
            btnAddGroup = new JButton();
            this.add(btnAddGroup, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            btnAddGroup.setText("Add a Group");
            btnAddGroup.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnAddGroupActionPerformed(evt);
                }
            });
        }
        {
            btnRemSelGrp = new JButton();
            this.add(btnRemSelGrp, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
            btnRemSelGrp.setText("Remove This Group");
            btnRemSelGrp.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    btnRemSelGrpActionPerformed(evt);
                }
            });
        }
        {
            btnEditPair = new JButton();
            this.add(btnEditPair, new GridBagConstraints(3, 4, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
            btnEditPair.setText("Edit This Pair");
            btnEditPair.setEnabled(false);
        }
        thisLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.1, 0.1, 0.0, 0.1, 0.0 };
        thisLayout.rowHeights = new int[] { 8, 24, 9, 20, 7, 8, 7, 9 };
        thisLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
        thisLayout.columnWidths = new int[] { 11, 335, 9, 97, 10, 119, 10 };
        this.setPreferredSize(new java.awt.Dimension(614, 382));
    } catch (Exception e) {
        e.printStackTrace();
    }
}