Example usage for javax.swing Box createHorizontalStrut

List of usage examples for javax.swing Box createHorizontalStrut

Introduction

In this page you can find the example usage for javax.swing Box createHorizontalStrut.

Prototype

public static Component createHorizontalStrut(int width) 

Source Link

Document

Creates an invisible, fixed-width component.

Usage

From source file:be.ac.ua.comp.scarletnebula.gui.DecoratedCommunicationPanel.java

final public void clearAndFill(final Collection<Server> selectedServers) {

    // Remove all components on there
    invalidate();//from  w  w w  .  j  av a 2s. c om
    removeAll();

    setLayout(new BorderLayout());

    // If there are no servers, or none of the servers are running, do not
    // display the ssh console
    final Collection<Server> connectableServers = new ArrayList<Server>();
    for (final Server s : selectedServers) {
        if (s.getStatus() == VmState.RUNNING && s.getPublicDnsAddress() != null) {
            connectableServers.add(s);
        }
    }

    // If there are no servers to connect to, don't draw the ssh console
    if (connectableServers.size() == 0) {
        log.info("Connection tab clicked and no servers selected to connect to.");
        final BetterTextLabel txt = new BetterTextLabel(
                "Please select at least one running server to connect to.");
        txt.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 20));
        add(txt, BorderLayout.CENTER);
        validate();
        repaint();
    } else {
        final Server connectServer = selectedServers.iterator().next();

        final JPanel propertiesPanel = new JPanel();
        propertiesPanel.setLayout(new BoxLayout(propertiesPanel, BoxLayout.LINE_AXIS));
        propertiesPanel.add(Box.createHorizontalGlue());
        final JButton propertiesButton = new JButton("Properties", Utils.icon("modify16.png"));
        propertiesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                final ChangeServerSshLoginMethodWindow win = new ChangeServerSshLoginMethodWindow(parent,
                        connectServer);
                win.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        clearAndFill(selectedServers);
                    }
                });
                win.setVisible(true);
            }
        });

        final JButton restartButton = new JButton("Restart connection", Utils.icon("undo16.png"));
        restartButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                clearAndFill(selectedServers);
            }
        });
        propertiesPanel.add(restartButton);
        propertiesPanel.add(Box.createHorizontalStrut(10));
        propertiesPanel.add(propertiesButton);
        propertiesPanel.add(Box.createHorizontalStrut(20));
        propertiesPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
        add(propertiesPanel, BorderLayout.NORTH);

        final SSHPanel sshPanel = new SSHPanel(connectServer);
        sshPanel.setBorder(BorderFactory.createEmptyBorder(5, 20, 10, 20));
        add(sshPanel, BorderLayout.CENTER);

        validate();
        repaint();
    }
}

From source file:com.eviware.soapui.impl.rest.panels.request.RestRequestDesktopPanel.java

private void addResourceAndQueryField(JXToolBar toolbar) {
    if (!(getRequest() instanceof RestTestRequestInterface)) {

        toolbar.addWithOnlyMinimumHeight(resourcePanel);

        toolbar.add(Box.createHorizontalStrut(4));

        toolbar.addWithOnlyMinimumHeight(queryPanel);
    }//from  w w w.  ja  va  2s. c om
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

IDABottomPanel(IDAVisualizerWindow masterFrame, RawDataFile dataFile, ParameterSet parameters) {

    this.dataFile = dataFile;
    this.masterFrame = masterFrame;

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    setBackground(Color.white);/*from ww w  .  ja  v  a  2  s  .  c  om*/
    setBorder(new EmptyBorder(5, 5, 5, 0));

    add(Box.createHorizontalGlue());

    GUIUtils.addLabel(this, "Show: ", SwingConstants.RIGHT);

    thresholdCombo = new JComboBox<Object>(PeakThresholdMode.values());
    thresholdCombo.setSelectedItem(PeakThresholdMode.NONE);
    thresholdCombo.setBackground(Color.white);
    thresholdCombo.setFont(smallFont);
    thresholdCombo.addActionListener(this);
    add(thresholdCombo);

    JPanel peakThresholdPanel = new JPanel();
    peakThresholdPanel.setBackground(Color.white);
    peakThresholdPanel.setLayout(new BoxLayout(peakThresholdPanel, BoxLayout.X_AXIS));

    GUIUtils.addLabel(peakThresholdPanel, "Value: ", SwingConstants.RIGHT);

    peakTextField = new JTextField();
    peakTextField.setPreferredSize(new Dimension(50, 15));
    peakTextField.setFont(smallFont);
    peakTextField.addActionListener(this);
    peakThresholdPanel.add(peakTextField);
    add(peakThresholdPanel);

    GUIUtils.addLabel(this, " from peak list: ", SwingConstants.RIGHT);

    peakListSelector = new JComboBox<PeakList>();
    peakListSelector.setBackground(Color.white);
    peakListSelector.setFont(smallFont);
    peakListSelector.addActionListener(masterFrame);
    peakListSelector.setActionCommand("PEAKLIST_CHANGE");
    add(peakListSelector);

    thresholdSettings = parameters.getParameter(IDAParameters.peakThresholdSettings);

    thresholdCombo.setSelectedItem(thresholdSettings.getMode());

    add(Box.createHorizontalStrut(10));

    add(Box.createHorizontalGlue());

}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsBottomPanel.java

MsMsBottomPanel(MsMsVisualizerWindow masterFrame, RawDataFile dataFile, ParameterSet parameters) {

    this.dataFile = dataFile;
    this.masterFrame = masterFrame;

    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    setBackground(Color.white);//from  ww  w .  j  a  va 2 s  .  c  om
    setBorder(new EmptyBorder(5, 5, 5, 0));

    add(Box.createHorizontalGlue());

    GUIUtils.addLabel(this, "Show: ", SwingConstants.RIGHT);

    thresholdCombo = new JComboBox<Object>(PeakThresholdMode.values());
    thresholdCombo.setSelectedItem(PeakThresholdMode.NONE);
    thresholdCombo.setBackground(Color.white);
    thresholdCombo.setFont(smallFont);
    thresholdCombo.addActionListener(this);
    add(thresholdCombo);

    JPanel peakThresholdPanel = new JPanel();
    peakThresholdPanel.setBackground(Color.white);
    peakThresholdPanel.setLayout(new BoxLayout(peakThresholdPanel, BoxLayout.X_AXIS));

    GUIUtils.addLabel(peakThresholdPanel, "Value: ", SwingConstants.RIGHT);

    peakTextField = new JTextField();
    peakTextField.setPreferredSize(new Dimension(50, 15));
    peakTextField.setFont(smallFont);
    peakTextField.addActionListener(this);
    peakThresholdPanel.add(peakTextField);
    add(peakThresholdPanel);

    GUIUtils.addLabel(this, " from peak list: ", SwingConstants.RIGHT);

    peakListSelector = new JComboBox<PeakList>();
    peakListSelector.setBackground(Color.white);
    peakListSelector.setFont(smallFont);
    peakListSelector.addActionListener(masterFrame);
    peakListSelector.setActionCommand("PEAKLIST_CHANGE");
    add(peakListSelector);

    thresholdSettings = parameters.getParameter(MsMsParameters.peakThresholdSettings);

    thresholdCombo.setSelectedItem(thresholdSettings.getMode());

    add(Box.createHorizontalStrut(10));

    add(Box.createHorizontalGlue());

}

From source file:UndoableToggleApp4.java

public UndoableToggleApp4() {

    // Create some toggle buttons (and subclasses).
    tog = new JToggleButton("ToggleButton");
    cb = new JCheckBox("CheckBox");
    radio = new JRadioButton("RadioButton");

    // Add our listener to the buttons.
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);/*from  w w w  .  java2s. c  o  m*/
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Lay out the buttons.
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo, redo, start, and end buttons.
    startButton = new JButton("Start");
    endButton = new JButton("End");
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    startButton.setEnabled(true);
    endButton.setEnabled(false);
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    // Add a listener to the start button. It creates a new StateEdit,
    // passing in this frame as the StateEditable.
    startButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit = new StateEdit(UndoableToggleApp4.this);
            startButton.setEnabled(false);
            endButton.setEnabled(true);
            //undoButton.setEnabled(edit.canUndo());
            //
            // NOTE: We really don't want to be able to undo until end() is
            // pressed,
            // but StateEdit does not enforce this for us!
            undoButton.setEnabled(false);
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Add a listener to the end button. It will call end() on the
    // StateEdit.
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            startButton.setEnabled(true);
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Add a redo listener: just like the undo listener.
    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Lay out the state/end and undo/redo buttons.
    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(startButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(endButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    // Lay out the main frame.
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:org.jdal.swing.form.SimpleBoxFormBuilder.java

/**
 * Gets current column pointed to cursor, create one if none.
 * @return a new or existent column Box.
 *///from   w  w w  .  j a v  a  2 s .  c o  m
private Box getColumn() {
    Box column = null;
    if (index < columns.size()) {
        column = (Box) columns.get(index);
    } else {
        if (!columns.isEmpty())
            container.add(Box.createHorizontalStrut(defaultSpace));

        column = Box.createVerticalBox();
        columns.add(column);
        container.add(column);
        columnsWidth.add(0);

        if (debug) {
            column.setBorder(BorderFactory.createLineBorder(Color.RED));
        }
    }
    return column;
}

From source file:org.jdal.swing.TableEditor.java

/**
 * Creates a new Box with table and actions buttons
 * @return a new Box/*from   w  ww.ja  va  2s .  c  o  m*/
 */
protected Container createTablePanel() {
    table = new JTable(tableModel, tableModel.getTableColumnModel());
    table.setRowHeight(22);
    table.setAutoCreateRowSorter(true);
    tableModel.addTableModelListener(this);
    JScrollPane scroll = new JScrollPane(table);
    scroll.setAlignmentX(Container.LEFT_ALIGNMENT);
    Box box = Box.createVerticalBox();
    JButton addButton = new JButton(new AddAction());
    JButton deleteButton = new JButton(new DeleteAction());
    JButton saveButton = new JButton(new SaveAction());
    JButton refreshButton = new JButton(new RefreshAction());
    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(addButton);
    buttonBox.add(Box.createHorizontalStrut(5));
    buttonBox.add(deleteButton);
    buttonBox.add(Box.createHorizontalStrut(5));
    buttonBox.add(saveButton);
    buttonBox.add(Box.createHorizontalStrut(5));
    buttonBox.add(refreshButton);
    buttonBox.setAlignmentX(Container.LEFT_ALIGNMENT);
    buttonBox.setMaximumSize(new Dimension(Short.MAX_VALUE, 25));
    box.add(buttonBox);
    box.add(Box.createVerticalStrut(5));
    box.add(scroll);
    return box;
}

From source file:com.apatar.ui.JFeatureRequestHelpDialog.java

private void createDialog() {
    setLayout(new BorderLayout(5, 5));

    setSize(400, 400);//from w ww . java2 s.co m

    JPanel textPanel = new JPanel(new BorderLayout(5, 5));
    textPanel.setBorder(new EmptyBorder(10, 5, 5, 5));
    text.setLineWrap(true);
    text.setWrapStyleWord(true);
    text.setFont(UiUtils.NORMAL_SIZE_12_FONT);

    textPanel.add(new JLabel("What new Apatar features would you like to request? Please describe them:"),
            BorderLayout.NORTH);
    textPanel.add(new JScrollPane(text), BorderLayout.CENTER);

    JPanel contactPanel = new JPanel();
    contactPanel.setLayout(new BoxLayout(contactPanel, BoxLayout.Y_AXIS));

    JPanel firstNamePanel = new JPanel();
    firstNamePanel.setLayout(new BoxLayout(firstNamePanel, BoxLayout.X_AXIS));
    firstNamePanel.add(new JLabel("Your First Name:"));
    firstNamePanel.add(Box.createHorizontalStrut(5));
    firstNamePanel.add(firstNameField);

    JPanel lastNamePanel = new JPanel();
    lastNamePanel.setLayout(new BoxLayout(lastNamePanel, BoxLayout.X_AXIS));
    lastNamePanel.add(new JLabel("Your Last Name:"));
    lastNamePanel.add(Box.createHorizontalStrut(5));
    lastNamePanel.add(lastNameField);

    JPanel emailPanel = new JPanel();
    emailPanel.setLayout(new BoxLayout(emailPanel, BoxLayout.X_AXIS));
    emailPanel.add(new JLabel("Your E-mail:"));
    emailPanel.add(Box.createHorizontalStrut(28));
    emailPanel.add(emailField);

    contactPanel.add(firstNamePanel);
    contactPanel.add(Box.createVerticalStrut(5));
    contactPanel.add(lastNamePanel);
    contactPanel.add(Box.createVerticalStrut(5));
    contactPanel.add(emailPanel);

    textPanel.add(contactPanel, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    buttonPanel.add(sendButton);
    buttonPanel.add(Box.createHorizontalStrut(5));
    buttonPanel.add(cancel);
    buttonPanel.add(Box.createHorizontalStrut(5));
    buttonPanel.setBorder(new EmptyBorder(0, 0, 5, 0));

    getContentPane().add(textPanel, BorderLayout.CENTER);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}

From source file:com.apatar.ui.JSubmitHelpDialog.java

private void createDialog() {
    setLayout(new BorderLayout(5, 5));

    setSize(400, 400);//  w ww  . ja  v a  2s  .co m

    JPanel textPanel = new JPanel(new BorderLayout(5, 5));
    textPanel.setBorder(new EmptyBorder(10, 5, 5, 5));
    text.setLineWrap(true);
    text.setWrapStyleWord(true);
    text.setFont(UiUtils.NORMAL_SIZE_12_FONT);

    textPanel.add(new JLabel("If you found a bug, please submit it here:"), BorderLayout.NORTH);
    textPanel.add(new JScrollPane(text), BorderLayout.CENTER);

    JPanel contactPanel = new JPanel();
    contactPanel.setLayout(new BoxLayout(contactPanel, BoxLayout.Y_AXIS));

    JPanel firstNamePanel = new JPanel();
    firstNamePanel.setLayout(new BoxLayout(firstNamePanel, BoxLayout.X_AXIS));
    firstNamePanel.add(new JLabel("Your First Name:"));
    firstNamePanel.add(Box.createHorizontalStrut(5));
    firstNamePanel.add(firstNameField);

    JPanel lastNamePanel = new JPanel();
    lastNamePanel.setLayout(new BoxLayout(lastNamePanel, BoxLayout.X_AXIS));
    lastNamePanel.add(new JLabel("Your Last Name:"));
    lastNamePanel.add(Box.createHorizontalStrut(5));
    lastNamePanel.add(lastNameField);

    JPanel emailPanel = new JPanel();
    emailPanel.setLayout(new BoxLayout(emailPanel, BoxLayout.X_AXIS));
    emailPanel.add(new JLabel("Your E-mail:"));
    emailPanel.add(Box.createHorizontalStrut(28));
    emailPanel.add(emailField);

    contactPanel.add(firstNamePanel);
    contactPanel.add(Box.createVerticalStrut(5));
    contactPanel.add(lastNamePanel);
    contactPanel.add(Box.createVerticalStrut(5));
    contactPanel.add(emailPanel);

    textPanel.add(contactPanel, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    buttonPanel.add(sendButton);
    buttonPanel.add(Box.createHorizontalStrut(5));
    buttonPanel.add(cancel);
    buttonPanel.add(Box.createHorizontalStrut(5));
    buttonPanel.setBorder(new EmptyBorder(0, 0, 5, 0));

    getContentPane().add(textPanel, BorderLayout.CENTER);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
}

From source file:components.ConversionPanel.java

ConversionPanel(Converter myController, String myTitle, Unit[] myUnits, ConverterRangeModel myModel) {
    if (MULTICOLORED) {
        setOpaque(true);//from  ww  w  . java2s  .  c o m
        setBackground(new Color(0, 255, 255));
    }
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(myTitle),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Save arguments in instance variables.
    controller = myController;
    units = myUnits;
    title = myTitle;
    sliderModel = myModel;

    //Create the text field format, and then the text field.
    numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMaximumFractionDigits(2);
    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setAllowsInvalid(false);
    formatter.setCommitsOnValidEdit(true);//seems to be a no-op --
    //aha -- it changes the value property but doesn't cause the result to
    //be parsed (that happens on focus loss/return, I think).
    //
    textField = new JFormattedTextField(formatter);
    textField.setColumns(10);
    textField.setValue(new Double(sliderModel.getDoubleValue()));
    textField.addPropertyChangeListener(this);

    //Add the combo box.
    unitChooser = new JComboBox();
    for (int i = 0; i < units.length; i++) { //Populate it.
        unitChooser.addItem(units[i].description);
    }
    unitChooser.setSelectedIndex(0);
    sliderModel.setMultiplier(units[0].multiplier);
    unitChooser.addActionListener(this);

    //Add the slider.
    slider = new JSlider(sliderModel);
    sliderModel.addChangeListener(this);

    //Make the text field/slider group a fixed size
    //to make stacked ConversionPanels nicely aligned.
    JPanel unitGroup = new JPanel() {
        public Dimension getMinimumSize() {
            return getPreferredSize();
        }

        public Dimension getPreferredSize() {
            return new Dimension(150, super.getPreferredSize().height);
        }

        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    unitGroup.setLayout(new BoxLayout(unitGroup, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        unitGroup.setOpaque(true);
        unitGroup.setBackground(new Color(0, 0, 255));
    }
    unitGroup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
    unitGroup.add(textField);
    unitGroup.add(slider);

    //Create a subpanel so the combo box isn't too tall
    //and is sufficiently wide.
    JPanel chooserPanel = new JPanel();
    chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.PAGE_AXIS));
    if (MULTICOLORED) {
        chooserPanel.setOpaque(true);
        chooserPanel.setBackground(new Color(255, 0, 255));
    }
    chooserPanel.add(unitChooser);
    chooserPanel.add(Box.createHorizontalStrut(100));

    //Put everything together.
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    add(unitGroup);
    add(chooserPanel);
    unitGroup.setAlignmentY(TOP_ALIGNMENT);
    chooserPanel.setAlignmentY(TOP_ALIGNMENT);
}