Example usage for java.awt GridBagConstraints BASELINE

List of usage examples for java.awt GridBagConstraints BASELINE

Introduction

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

Prototype

int BASELINE

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

Click Source Link

Document

Possible value for the anchor field.

Usage

From source file:com.jostrobin.battleships.view.panels.PlacementPanel.java

@Override
public void afterPropertiesSet() throws Exception {
    setLayout(new GridBagLayout());

    battleField = new BattleFieldPanel("");
    GridBagConstraints gamePanelConstraints = new GridBagConstraints();
    gamePanelConstraints.weightx = 0.6;/*from ww w . ja  v  a  2 s.  co m*/
    gamePanelConstraints.weighty = 1.0;
    gamePanelConstraints.gridy = y;
    gamePanelConstraints.gridheight = 4;
    gamePanelConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    gamePanelConstraints.fill = GridBagConstraints.BOTH;
    add(battleField, gamePanelConstraints);

    rotate = new JButton("Rotate ship");
    rotate.addActionListener(this);
    GridBagConstraints leftButtonConstraints = new GridBagConstraints();
    leftButtonConstraints.gridy = y++;
    leftButtonConstraints.gridx = 1;
    leftButtonConstraints.fill = GridBagConstraints.NONE;
    leftButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    add(rotate, leftButtonConstraints);

    random = new JButton("Random");
    random.addActionListener(this);
    GridBagConstraints randomButtonConstraints = new GridBagConstraints();
    randomButtonConstraints.gridy = y++;
    randomButtonConstraints.gridx = 1;
    randomButtonConstraints.fill = GridBagConstraints.NONE;
    randomButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    random.addActionListener(this);
    add(random, randomButtonConstraints);

    shipsPanel = new ShipsPanel();
    GridBagConstraints shipsPanelConstraints = new GridBagConstraints();
    shipsPanelConstraints.weightx = 1.0;
    shipsPanelConstraints.weighty = 1.0;
    shipsPanelConstraints.anchor = GridBagConstraints.BASELINE;
    shipsPanelConstraints.fill = GridBagConstraints.BOTH;
    shipsPanelConstraints.gridy = y++;
    shipsPanelConstraints.gridx = 1;
    add(shipsPanel, shipsPanelConstraints);

    ready = new JButton("I'm ready");
    ready.addActionListener(this);
    GridBagConstraints readyButtonConstraints = new GridBagConstraints();
    readyButtonConstraints.gridy = y++;
    readyButtonConstraints.gridx = 1;
    readyButtonConstraints.anchor = GridBagConstraints.ABOVE_BASELINE;
    ready.setEnabled(false);
    add(ready, readyButtonConstraints);

    updateShips();
}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

void updateModesPanel() {
    if (modesListPanel == null)
        return;//w ww  .  j  a v a  2 s  . c  om

    modesListPanel.removeAll();

    final var modes = input.getProfile().getModes();
    for (var i = 0; i < modes.size(); i++) {
        final var mode = modes.get(i);

        final var modePanel = new JPanel(new GridBagLayout());
        modesListPanel.add(modePanel,
                new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
                        GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL,
                        new Insets(0, 0, 0, 0), 0, 5));

        final var modeNoLabel = new JLabel(rb.getString("MODE_NO_LABEL_PREFIX") + (i + 1));
        modeNoLabel.setPreferredSize(new Dimension(100, 15));
        modePanel.add(modeNoLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BASELINE,
                GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        modePanel.add(Box.createGlue(), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var descriptionTextField = new JTextField(mode.getDescription(), 20);
        modePanel.add(descriptionTextField, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var setModeDescriptionAction = new SetModeDescriptionAction(mode, descriptionTextField);
        descriptionTextField.addActionListener(setModeDescriptionAction);
        descriptionTextField.getDocument().addDocumentListener(setModeDescriptionAction);

        modePanel.add(Box.createGlue(), new GridBagConstraints(3, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        if (Profile.defaultMode.equals(mode) || OnScreenKeyboard.onScreenKeyboardMode.equals(mode)) {
            descriptionTextField.setEditable(false);
            modePanel.add(Box.createHorizontalStrut(BUTTON_DIMENSION.width));
        } else {
            final var deleteButton = new JButton(new RemoveModeAction(mode));
            deleteButton.setPreferredSize(BUTTON_DIMENSION);
            modePanel.add(deleteButton, new GridBagConstraints(4, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
                    GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        }
    }

    modesListPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0,
            GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    modesScrollPane.setViewportView(modesListPanel);
}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private void updateOverlayPanel() {
    if (indicatorsListPanel == null)
        return;/*from   w  w w  .  java  2  s . com*/

    indicatorsListPanel.removeAll();

    for (final var virtualAxis : Input.VirtualAxis.values()) {
        final var indicatorPanel = new JPanel(new GridBagLayout());
        indicatorsListPanel.add(indicatorPanel,
                new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
                        GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL,
                        new Insets(0, 0, 0, 0), 0, 5));

        final var virtualAxisLabel = new JLabel(virtualAxis.toString() + rb.getString("AXIS_LABEL_SUFFIX"));
        virtualAxisLabel.setPreferredSize(new Dimension(100, 15));
        indicatorPanel.add(virtualAxisLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var virtualAxisToOverlayAxisMap = input.getProfile().getVirtualAxisToOverlayAxisMap();
        final var overlayAxis = virtualAxisToOverlayAxisMap.get(virtualAxis);
        final var enabled = overlayAxis != null;

        final var colorLabel = new JLabel();
        if (enabled) {
            colorLabel.setOpaque(true);
            colorLabel.setBackground(overlayAxis.color);
        } else
            colorLabel.setText(rb.getString("INDICATOR_DISABLED_LABEL"));
        colorLabel.setHorizontalAlignment(SwingConstants.CENTER);

        colorLabel.setPreferredSize(new Dimension(100, 15));
        colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        indicatorPanel.add(colorLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BASELINE,
                GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var colorButton = new JButton(new SelectIndicatorColorAction(virtualAxis));
        colorButton.setPreferredSize(BUTTON_DIMENSION);
        colorButton.setEnabled(enabled);
        indicatorPanel.add(colorButton, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var invertedCheckBox = new JCheckBox(new InvertIndicatorAction(virtualAxis));
        invertedCheckBox.setSelected(enabled && overlayAxis.inverted);
        invertedCheckBox.setEnabled(enabled);
        indicatorPanel.add(invertedCheckBox, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0,
                GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

        final var displayCheckBox = new JCheckBox(new DisplayIndicatorAction(virtualAxis));
        displayCheckBox.setSelected(enabled);
        indicatorPanel.add(displayCheckBox, new GridBagConstraints(4, GridBagConstraints.RELATIVE, 1, 1, 0.0,
                0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    }

    indicatorsListPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0,
            1.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    indicatorsScrollPane.setViewportView(indicatorsListPanel);
}

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

private void initLayout() {
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    {//layout top bar
        JPanel bar = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.BASELINE;
        gbc.insets = new Insets(8, 6, 8, 2);
        bar.add(new JLabel("Select Template:"), gbc);
        gbc.insets = new Insets(8, 2, 8, 6);
        gbc.weightx = 1;/* www.  j  av  a2  s  .  c o m*/
        bar.add(sheetBox, gbc);
        pane.add(bar, BorderLayout.NORTH);
    }
    {
        Box vbox = Box.createVerticalBox();
        previewPanelParent.setPreferredSize(new Dimension(600, 800));
        vbox.add(previewPanelParent);
        vbox.add(progressBar);
        pane.add(vbox, BorderLayout.CENTER);
    }
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(new JLabel("Page:"));
        hbox.add(Box.createHorizontalStrut(4));
        hbox.add(pageBox);
        hbox.add(Box.createHorizontalStrut(10));
        hbox.add(new JLabel("Zoom:"));
        hbox.add(Box.createHorizontalStrut(4));
        hbox.add(zoomBox);
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(zoomInButton);
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(zoomOutButton);
        hbox.add(Box.createHorizontalGlue());
        hbox.add(printButton);
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(cancelButton);
        hbox.setBorder(BorderFactory.createEmptyBorder(8, 5, 8, 5));
        pane.add(hbox, BorderLayout.SOUTH);
    }
}