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:com.diversityarrays.util.DatePickerDialog.java

public DatePickerDialog(Window owner, String title, Closure<Date> onComplete) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    this.onComplete = onComplete;

    datePicker.getMonthView().setZoomable(true);
    datePicker.setLinkPanel(null);//from w  w  w. j  a v  a  2  s .  c o  m
    datePicker.setFormats(getDefaultDateFormats());

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(cancel));
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(new JButton(save));
    buttons.add(Box.createHorizontalGlue());

    Container cp = getContentPane();
    cp.add(datePicker.getMonthView(), BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);

    pack();
}

From source file:RGBAColourChooser.java

/**
 * Constructs a new RGBAColourChooser/*  w  w w .ja  v  a  2 s.c om*/
 */
public RGBAColourChooser() {
    super(BoxLayout.X_AXIS);

    Box rb = new Box(BoxLayout.X_AXIS);
    rb.add(redLabel);
    rb.add(redSlider);
    Box gb = new Box(BoxLayout.X_AXIS);
    gb.add(greenLabel);
    gb.add(greenSlider);
    Box bb = new Box(BoxLayout.X_AXIS);
    bb.add(blueLabel);
    bb.add(blueSlider);
    Box ab = new Box(BoxLayout.X_AXIS);
    ab.add(alphaLabel);
    ab.add(alphaSlider);

    redSlider.setValue(oldValue.getRed());
    greenSlider.setValue(oldValue.getGreen());
    blueSlider.setValue(oldValue.getBlue());
    alphaSlider.setValue(oldValue.getAlpha());

    redSlider.addChangeListener(this);
    greenSlider.addChangeListener(this);
    blueSlider.addChangeListener(this);
    alphaSlider.addChangeListener(this);

    redSlider.setToolTipText(String.valueOf(redSlider.getValue()));
    greenSlider.setToolTipText(String.valueOf(greenSlider.getValue()));
    blueSlider.setToolTipText(String.valueOf(blueSlider.getValue()));
    alphaSlider.setToolTipText(String.valueOf(alphaSlider.getValue()));

    sliderBox = new Box(BoxLayout.Y_AXIS);
    sliderBox.add(rb);
    sliderBox.add(gb);
    sliderBox.add(bb);
    sliderBox.add(ab);

    add(previewer);
    add(Box.createHorizontalStrut(5));
    add(sliderBox);

}

From source file:components.ListDemo.java

public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();
    listModel.addElement("Jane Doe");
    listModel.addElement("John Smith");
    listModel.addElement("Kathy Green");

    //Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);/*from w  w  w .j a  v  a2 s. c om*/
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();

    //Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
}

From source file:BoxLayoutPane.java

public BoxLayoutPane() {
    // Use a BorderLayout layout manager to arrange various Box components
    this.setLayout(new BorderLayout());

    // Give the entire panel a margin by adding an empty border
    // We could also do this by overriding getInsets()
    this.setBorder(new EmptyBorder(10, 10, 10, 10));

    // Add a plain row of buttons along the top of the pane
    Box row = Box.createHorizontalBox();
    for (int i = 0; i < 4; i++) {
        JButton b = new JButton("B" + i);
        b.setFont(new Font("serif", Font.BOLD, 12 + i * 2));
        row.add(b);/*  ww w . j  av a 2s . c  o m*/
    }
    this.add(row, BorderLayout.NORTH);

    // Add a plain column of buttons along the right edge
    // Use BoxLayout with a different kind of Swing container
    // Give the column a border: can't do this with the Box class
    JPanel col = new JPanel();
    col.setLayout(new BoxLayout(col, BoxLayout.Y_AXIS));
    col.setBorder(new TitledBorder(new EtchedBorder(), "Column"));
    for (int i = 0; i < 4; i++) {
        JButton b = new JButton("Button " + i);
        b.setFont(new Font("sanserif", Font.BOLD, 10 + i * 2));
        col.add(b);
    }
    this.add(col, BorderLayout.EAST); // Add column to right of panel

    // Add a button box along the bottom of the panel.
    // Use "Glue" to space the buttons evenly
    Box buttonbox = Box.createHorizontalBox();
    buttonbox.add(Box.createHorizontalGlue()); // stretchy space
    buttonbox.add(new JButton("Okay"));
    buttonbox.add(Box.createHorizontalGlue()); // stretchy space
    buttonbox.add(new JButton("Cancel"));
    buttonbox.add(Box.createHorizontalGlue()); // stretchy space
    buttonbox.add(new JButton("Help"));
    buttonbox.add(Box.createHorizontalGlue()); // stretchy space
    this.add(buttonbox, BorderLayout.SOUTH);

    // Create a component to display in the center of the panel
    JTextArea textarea = new JTextArea();
    textarea.setText("This component has 12-pixel margins on left and top"
            + " and has 72-pixel margins on right and bottom.");
    textarea.setLineWrap(true);
    textarea.setWrapStyleWord(true);

    // Use Box objects to give the JTextArea an unusual spacing
    // First, create a column with 3 kids. The first and last kids
    // are rigid spaces. The middle kid is the text area
    Box fixedcol = Box.createVerticalBox();
    fixedcol.add(Box.createVerticalStrut(12)); // 12 rigid pixels
    fixedcol.add(textarea); // Component fills in the rest
    fixedcol.add(Box.createVerticalStrut(72)); // 72 rigid pixels

    // Now create a row. Give it rigid spaces on the left and right,
    // and put the column from above in the middle.
    Box fixedrow = Box.createHorizontalBox();
    fixedrow.add(Box.createHorizontalStrut(12));
    fixedrow.add(fixedcol);
    fixedrow.add(Box.createHorizontalStrut(72));

    // Now add the JTextArea in the column in the row to the panel
    this.add(fixedrow, BorderLayout.CENTER);
}

From source file:UndoableToggleApp4.java

public UndoableToggleApp4() {
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//ww w.j a v a 2 s.  c  om
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    startButton.setEnabled(true);
    endButton.setEnabled(false);
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    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());
        }
    });

    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());
            }
        }
    });

    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:com.intuit.tank.proxy.settings.ui.ProxyConfigDialog.java

private JToolBar getToolbar() {
    if (toolbar == null) {
        toolbar = new JToolBar();
        JButton saveButton = new JButton("Save",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveButton.addActionListener(new ActionListener() {
            @Override/*w w w .j  av  a  2 s  .  co  m*/
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(false);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton saveasButton = new JButton("Save As...",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/save_as.png")));
        saveasButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    saveConfig(true);
                } catch (IOException e1) {
                    throw new IllegalArgumentException(e1);
                }
            }
        });
        JButton openButton = new JButton("Open",
                new ImageIcon(ProxyConfigDialog.class.getResource("/icons/16/open_folder.png")));
        openButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                openConfig();
            }
        });
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(openButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveButton);
        toolbar.add(Box.createHorizontalStrut(5));
        toolbar.add(saveasButton);
    }

    return toolbar;
}

From source file:UndoableToggleApp2.java

public UndoableToggleApp2() {

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

    // Add our listener to each toggle button
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);/*from   w  w  w  .j  av a2 s. 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 and redo buttons (initially disabled)
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    endButton = new JButton("End");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);
    endButton.setEnabled(false);

    // 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, but for redo this
    // time.
    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());
            }
        }
    });

    // Add an end listener. This listener will call end() on the
    // CompoundEdit
    // and update the undo/redo buttons.
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Layout the undo/redo/end buttons
    Box undoRedoEndBox = new Box(BoxLayout.X_AXIS);
    undoRedoEndBox.add(Box.createGlue());
    undoRedoEndBox.add(undoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(redoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(endButton);
    undoRedoEndBox.add(Box.createGlue());

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

From source file:net.sf.jhylafax.AbstractFaxDialog.java

protected void addNumberTextField() {
    Box box = Box.createHorizontalBox();

    addressBookAction = new AddressBookAction();

    numberTextField = new JTextField();
    numberTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE, numberTextField.getPreferredSize().height));
    numberTextField.setTransferHandler(new ContactTransferHandler());
    //numberTextField.setDragEnabled(true);
    box.add(numberTextField);/*from w  w w  .  j  a  va  2  s  .  c  o m*/
    box.add(Box.createHorizontalStrut(4));
    box.add(Builder.createIconButton(addressBookAction));
    numberLabel = builder.append("", box, 4);
    builder.nextLine();

    numberCompletionModel = new DefaultCompletionModel();
    numberCompletion = Builder.addCompletion(numberTextField, numberCompletionModel);

    new CompletionSettingDirector(Settings.backstore, "number").restore(numberCompletion);
}

From source file:ListDemo.java

public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();
    listModel.addElement("Debbie Scott");
    listModel.addElement("Scott Hommel");
    listModel.addElement("Sharon Zakhour");

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);/*from  www . j a  va 2s  . com*/
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();

    // Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
}

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

private JPanel getBottomPanel() {
    final JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
    bottomPanel.add(Box.createHorizontalGlue());
    final JButton cancelButton = ButtonFactory.createCancelButton();
    cancelButton.addActionListener(new ActionListener() {
        @Override//from w  w  w . ja v a  2s  .  c  o m
        public void actionPerformed(final ActionEvent e) {
            LinkUnlinkWindow.this.dispose();
        }
    });

    bottomPanel.add(cancelButton);
    bottomPanel.add(Box.createHorizontalStrut(10));
    final JButton okButton = ButtonFactory.createOkButton();
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actuallyLinkUnlink();
            LinkUnlinkWindow.this.dispose();
        }
    });

    bottomPanel.add(okButton);
    bottomPanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 20, 20));
    return bottomPanel;
}