Example usage for javax.swing Box add

List of usage examples for javax.swing Box add

Introduction

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

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:org.jdal.swing.report.ReportFileView.java

@Override
protected JComponent buildPanel() {
    Box box = Box.createHorizontalBox();

    fileName.setEditable(false);/*from  w w w .j  ava  2  s  . co  m*/

    box.add(new JLabel("Fichero"));
    box.add(fileName);
    box.add(Box.createHorizontalStrut(5));

    box.add(Box.createHorizontalStrut(5));
    box.add(new JButton(new FileAction()));

    return box;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.SaveChartDialog.java

/**
 * Creates and lays out the controls inside this dialog's content pane.
 * <p>//from   www.j  a va 2 s  .com
 * This method is called upon initialization only.
 * </p>
 */
private void initControls() {
    JPanel sizePanel = new JPanel(new GridLayout(2, 3, 4, 4));
    sizePanel.setBorder(BorderFactory.createTitledBorder(Messages.DI_IMAGESIZE));

    // Add a spinner for choosing width
    sizePanel.add(new JLabel(Messages.DI_WIDTH, SwingConstants.RIGHT));
    int width = ChartPanel.DEFAULT_WIDTH;
    int minWidth = ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH;
    int maxWidth = ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH;
    SpinnerModel widthSettings = new SpinnerNumberModel(width, minWidth, maxWidth, 1);
    sizePanel.add(widthSpinner = new JSpinner(widthSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add a spinner for choosing height
    sizePanel.add(new JLabel(Messages.DI_HEIGHT, SwingConstants.RIGHT));
    int height = ChartPanel.DEFAULT_HEIGHT;
    int minHeight = ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT;
    int maxHeight = ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT;
    SpinnerModel heightSettings = new SpinnerNumberModel(height, minHeight, maxHeight, 1);
    sizePanel.add(heightSpinner = new JSpinner(heightSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add Save and Cancel buttons
    JPanel buttons = new JPanel(new GridLayout(1, 2, 4, 0));
    buttons.add(btnSave = Utils.createButton(Messages.DI_SAVE, null, this));
    buttons.add(btnCancel = Utils.createButton(Messages.DI_CANCEL, null, this));
    Box buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(Box.createHorizontalGlue());
    buttonsBox.add(buttons);
    buttonsBox.add(Box.createHorizontalGlue());

    Container contentPane = getContentPane();
    contentPane.add(sizePanel, BorderLayout.NORTH);
    contentPane.add(Box.createVerticalStrut(Utils.BORDER_SIZE / 2));
    contentPane.add(buttonsBox, BorderLayout.PAGE_END);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Utils.setStandardBorder(getRootPane());
}

From source file:org.stanwood.swing.AboutDialog.java

private JComponent createAboutTab() {
    JScrollPane scroll = new JScrollPane();
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    Box box = Box.createVerticalBox();
    box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    box.add(Box.createVerticalGlue());
    if (message != null) {
        JXLabel lblMessage = new JXLabel(message);
        lblMessage.setLineWrap(true);//from   w  w w.j a v  a2 s .  c  o m
        box.add(lblMessage);
    }
    if (appUrl != null) {
        JXHyperlink link = new JXHyperlink(new LinkAction(this, appUrl, appUrl));
        box.add(link);
    }
    box.add(Box.createVerticalGlue());
    scroll.getViewport().add(box);
    return scroll;
}

From source file:sample.fa.ScriptRunnerApplication.java

void createGUI() {
    Box buttonBox = Box.createHorizontalBox();

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(this::loadScript);
    buttonBox.add(loadButton);

    JButton saveButton = new JButton("Save");
    saveButton.addActionListener(this::saveScript);
    buttonBox.add(saveButton);//from w w  w  .j  ava  2 s  .  com

    JButton executeButton = new JButton("Execute");
    executeButton.addActionListener(this::executeScript);
    buttonBox.add(executeButton);

    languagesModel = new DefaultComboBoxModel();

    ScriptEngineManager sem = new ScriptEngineManager();
    for (ScriptEngineFactory sef : sem.getEngineFactories()) {
        languagesModel.addElement(sef.getScriptEngine());
    }

    JComboBox<ScriptEngine> languagesCombo = new JComboBox<>(languagesModel);
    JLabel languageLabel = new JLabel();
    languagesCombo.setRenderer((JList<? extends ScriptEngine> list, ScriptEngine se, int index,
            boolean isSelected, boolean cellHasFocus) -> {
        ScriptEngineFactory sef = se.getFactory();
        languageLabel.setText(sef.getEngineName() + " - " + sef.getLanguageName() + " (*."
                + String.join(", *.", sef.getExtensions()) + ")");
        return languageLabel;
    });
    buttonBox.add(Box.createHorizontalGlue());
    buttonBox.add(languagesCombo);

    scriptContents = new JTextArea();
    scriptContents.setRows(8);
    scriptContents.setColumns(40);

    scriptResults = new JTextArea();
    scriptResults.setEditable(false);
    scriptResults.setRows(8);
    scriptResults.setColumns(40);

    JSplitPane jsp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scriptContents, scriptResults);

    JFrame frame = new JFrame("Script Runner");
    frame.add(buttonBox, BorderLayout.NORTH);
    frame.add(jsp, BorderLayout.CENTER);

    frame.pack();
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setVisible(true);
}

From source file:fll.scheduler.SchedulerUI.java

/**
 * Prompt the user for which columns represent subjective categories.
 * //from w  ww  . ja  v  a 2  s .  co  m
 * @param parentComponent the parent for the dialog
 * @param columnInfo the column information
 * @return the list of subjective information the user choose
 */
public static List<SubjectiveStation> gatherSubjectiveStationInformation(final Component parentComponent,
        final ColumnInformation columnInfo) {
    final List<String> unusedColumns = columnInfo.getUnusedColumns();
    final List<JCheckBox> checkboxes = new LinkedList<JCheckBox>();
    final List<JFormattedTextField> subjectiveDurations = new LinkedList<JFormattedTextField>();
    final Box optionPanel = Box.createVerticalBox();

    optionPanel.add(new JLabel("Specify which columns in the data file are for subjective judging"));

    final JPanel grid = new JPanel(new GridLayout(0, 2));
    optionPanel.add(grid);
    grid.add(new JLabel("Data file column"));
    grid.add(new JLabel("Duration (minutes)"));

    for (final String column : unusedColumns) {
        if (null != column && column.length() > 0) {
            final JCheckBox checkbox = new JCheckBox(column);
            checkboxes.add(checkbox);
            final JFormattedTextField duration = new JFormattedTextField(
                    Integer.valueOf(SchedParams.DEFAULT_SUBJECTIVE_MINUTES));
            duration.setColumns(4);
            subjectiveDurations.add(duration);
            grid.add(checkbox);
            grid.add(duration);
        }
    }
    final List<SubjectiveStation> subjectiveHeaders;
    if (!checkboxes.isEmpty()) {
        JOptionPane.showMessageDialog(parentComponent, optionPanel, "Choose Subjective Columns",
                JOptionPane.QUESTION_MESSAGE);
        subjectiveHeaders = new LinkedList<SubjectiveStation>();
        for (int i = 0; i < checkboxes.size(); ++i) {
            final JCheckBox box = checkboxes.get(i);
            final JFormattedTextField duration = subjectiveDurations.get(i);
            if (box.isSelected()) {
                subjectiveHeaders
                        .add(new SubjectiveStation(box.getText(), ((Number) duration.getValue()).intValue()));
            }
        }
    } else {
        subjectiveHeaders = Collections.emptyList();
    }

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Subjective headers selected: " + subjectiveHeaders);
    }
    return subjectiveHeaders;
}

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

private void initComponents() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

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

        @Override//from ww  w.  j  av a2s . co m
        public TableCellEditor getCellEditor(int row, int column) {
            if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {//TODO: the max roll should be calculated in a different manner
                String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD();
                int max = NumberUtils.toInt(hd);
                return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1));
            }
            return super.getCellEditor(row, column);
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {
                return new SpinnerRenderer();
            }
            return super.getCellRenderer(row, column);
        }

    };
    table.setCellSelectionEnabled(false);
    table.setRowHeight(new JSpinner().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(Box.createHorizontalGlue());
    JButton button = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$
    button.setActionCommand("Close"); //$NON-NLS-1$
    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);
        }

    });

    Utility.installEscapeCloseOperation(this);
}

From source file:edu.gmu.cs.sim.util.media.chart.XYChartGenerator.java

protected void buildGlobalAttributes(LabelledList list) {

    // create the chart
    ((XYPlot) (chart.getPlot())).setDomainGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setDomainGridlinePaint(new Color(200, 200, 200));
    ((XYPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200));

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);/*from w w  w  .  java 2s.c o  m*/
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    xLog = new JCheckBox();
    xLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (xLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(xLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setDomainAxis(logAxis);
            } else {
                chart.getXYPlot().setDomainAxis(new NumberAxis(xLabel.getValue()));
            }
        }
    });

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setRangeAxis(logAxis);
            } else {
                chart.getXYPlot().setRangeAxis(new NumberAxis(yLabel.getValue()));
            }
        }
    });

    Box box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xLog);
    box.add(new JLabel(" Y"));
    box.add(yLog);
    box.add(Box.createGlue());
    list.add(new JLabel("Log Axis"), box);

    final JCheckBox xgridlines = new JCheckBox();
    xgridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setDomainGridlinesVisible(true);
            } else {
                chart.getXYPlot().setDomainGridlinesVisible(false);
            }
        }
    };
    xgridlines.addItemListener(il);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setRangeGridlinesVisible(true);
            } else {
                chart.getXYPlot().setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xgridlines);
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Grid Lines"), box);
}

From source file:components.FrameDemo2.java

protected JComponent createOptionControls() {
    JLabel label1 = new JLabel("Decoration options for subsequently created frames:");
    ButtonGroup bg1 = new ButtonGroup();
    JLabel label2 = new JLabel("Icon options:");
    ButtonGroup bg2 = new ButtonGroup();

    //Create the buttons
    JRadioButton rb1 = new JRadioButton();
    rb1.setText("Look and feel decorated");
    rb1.setActionCommand(LF_DECORATIONS);
    rb1.addActionListener(this);
    rb1.setSelected(true);/*  w w w. ja v a2  s. co  m*/
    bg1.add(rb1);
    //
    JRadioButton rb2 = new JRadioButton();
    rb2.setText("Window system decorated");
    rb2.setActionCommand(WS_DECORATIONS);
    rb2.addActionListener(this);
    bg1.add(rb2);
    //
    JRadioButton rb3 = new JRadioButton();
    rb3.setText("No decorations");
    rb3.setActionCommand(NO_DECORATIONS);
    rb3.addActionListener(this);
    bg1.add(rb3);
    //
    //
    JRadioButton rb4 = new JRadioButton();
    rb4.setText("Default icon");
    rb4.setActionCommand(DEFAULT_ICON);
    rb4.addActionListener(this);
    rb4.setSelected(true);
    bg2.add(rb4);
    //
    JRadioButton rb5 = new JRadioButton();
    rb5.setText("Icon from a JPEG file");
    rb5.setActionCommand(FILE_ICON);
    rb5.addActionListener(this);
    bg2.add(rb5);
    //
    JRadioButton rb6 = new JRadioButton();
    rb6.setText("Painted icon");
    rb6.setActionCommand(PAINT_ICON);
    rb6.addActionListener(this);
    bg2.add(rb6);

    //Add everything to a container.
    Box box = Box.createVerticalBox();
    box.add(label1);
    box.add(Box.createVerticalStrut(5)); //spacer
    box.add(rb1);
    box.add(rb2);
    box.add(rb3);
    //
    box.add(Box.createVerticalStrut(15)); //spacer
    box.add(label2);
    box.add(Box.createVerticalStrut(5)); //spacer
    box.add(rb4);
    box.add(rb5);
    box.add(rb6);

    //Add some breathing room.
    box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    return box;
}

From source file:net.sf.vfsjfilechooser.accessories.bookmarks.BookmarksManagerPanel.java

public BookmarksManagerPanel(BookmarksDialog parentDialog, VFSJFileChooser chooser) {
    this.parentDialog = parentDialog;
    this.chooser = chooser;

    model = new Bookmarks();

    table = new JTable(model);
    scrollPane = new JScrollPane(table);

    table.setPreferredScrollableViewportSize(tableSize);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    bCancel = new JButton(VFSResources.getMessage("VFSJFileChooser.closeButtonText"));

    bOpen = new JButton(VFSResources.getMessage("VFSJFileChooser.openButtonText"));
    bOpen.setIcon(//w w w .j a v a  2 s  .  co m
            new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/document-open.png")));
    bOpen.setHorizontalAlignment(SwingConstants.LEFT);

    bAdd = new JButton(VFSResources.getMessage("VFSJFileChooser.addButtonText"));
    bAdd.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/list-add.png")));
    bAdd.setHorizontalAlignment(SwingConstants.LEFT);

    bEdit = new JButton(VFSResources.getMessage("VFSJFileChooser.editButtonText"));
    bEdit.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/book_edit.png")));
    bEdit.setHorizontalAlignment(SwingConstants.LEFT);

    bDelete = new JButton(VFSResources.getMessage("VFSJFileChooser.deleteButtonText"));
    bDelete.setIcon(
            new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/list-remove.png")));
    bDelete.setHorizontalAlignment(SwingConstants.LEFT);

    bMoveUp = new JButton(VFSResources.getMessage("VFSJFileChooser.moveUpButtonText"));
    bMoveUp.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/go-up.png")));
    bMoveUp.setHorizontalAlignment(SwingConstants.LEFT);

    bMoveDown = new JButton(VFSResources.getMessage("VFSJFileChooser.moveDownButtonText"));
    bMoveDown.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/go-down.png")));
    bMoveDown.setHorizontalAlignment(SwingConstants.LEFT);

    final ActionHandler ah = new ActionHandler();

    bOpen.addActionListener(ah);
    bCancel.addActionListener(ah);
    bEdit.addActionListener(ah);
    bAdd.addActionListener(ah);
    bDelete.addActionListener(ah);
    bMoveUp.addActionListener(ah);
    bMoveDown.addActionListener(ah);

    final Box south = Box.createHorizontalBox();
    south.add(Box.createHorizontalGlue());
    south.add(bCancel);
    south.add(Box.createHorizontalGlue());

    final JPanel buttons = new JPanel(new GridLayout(0, 1, 5, 5));

    buttons.add(bAdd);
    buttons.add(bEdit);
    buttons.add(bDelete);
    buttons.add(bOpen);
    buttons.add(Box.createVerticalStrut(10));
    buttons.add(bMoveUp);
    buttons.add(bMoveDown);

    JPanel east = new JPanel();
    east.add(buttons, BorderLayout.NORTH);
    east.add(new JPanel(), BorderLayout.CENTER); // don't ask

    setLayout(new BorderLayout(10, 10));

    add(scrollPane, BorderLayout.CENTER);
    add(south, BorderLayout.SOUTH);
    add(east, BorderLayout.EAST);

    setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, UIManager.getColor("Panel.background")));
}

From source file:net.ontopia.topicmaps.viz.AboutFrame.java

private Component createImagePanel() {
    Box main = new Box(BoxLayout.X_AXIS);
    Icon aboutImage = this.getAboutImage();
    JLabel imageLabel;// w w w .  j  a v  a 2 s .  c o  m
    if (aboutImage == null)
        imageLabel = new JLabel("Ontopia AS - The TopicMap People");
    else
        imageLabel = new JLabel(aboutImage);
    main.add(imageLabel);
    return main;
}