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:com.diversityarrays.kdxplore.field.CollectionPathPanel.java

public CollectionPathPanel(boolean wantPlotsPerGroup, BiConsumer<VisitOrder2D, PlotsPerGroup> onChoiceChanged,
        List<? extends OrOrTr> onlyThese) {
    super(new BorderLayout());

    plotsPerGroupChoice.setSelectedItem(plotsPerGroup);
    odtChoicePanel.setOrOrTr(visitOrder);

    this.onChoiceChanged = onChoiceChanged;

    if (wantPlotsPerGroup) {
        plotsPerGroupChoice.addItemListener(new ItemListener() {
            @Override//from ww w .j av  a 2  s .c om
            public void itemStateChanged(ItemEvent e) {
                plotsPerGroup = (PlotsPerGroup) plotsPerGroupChoice.getSelectedItem();
                onChoiceChanged.accept(visitOrder, plotsPerGroup);
            }
        });

        Box top = Box.createHorizontalBox();
        top.add(new JLabel("Plots Per Group:"));
        top.add(plotsPerGroupChoice);
        top.add(Box.createHorizontalGlue());

        add(top, BorderLayout.NORTH);
    }

    if (!Check.isEmpty(onlyThese)) {
        OrOrTr first = onlyThese.get(0);

        odtChoicePanel.setOnlyAllow(onlyThese.toArray(new OrOrTr[onlyThese.size()]));

        String msg;
        if (onlyThese.size() == 1) {
            msg = "<HTML>For now, only supporting:<BR>" + onlyThese.get(0).toString();
        } else {
            msg = onlyThese.stream().map(oot -> oot.toString())
                    .collect(Collectors.joining("<BR>", "<HTML>For now, only supporting:<BR>", ""));
        }

        JLabel label = new JLabel(msg, JLabel.CENTER);
        label.setForeground(Color.RED);
        add(label, BorderLayout.SOUTH);
    }

    add(odtChoicePanel, BorderLayout.CENTER);
}

From source file:com.diversityarrays.kdxplore.design.SheetChooserPanel.java

public SheetChooserPanel(BackgroundRunner br, Consumer<String> onSheetChosen /*, Component ... more */) {
    super(new BorderLayout());

    this.backgroundRunner = br;
    this.onChoice = onSheetChosen;
    sheetComboBox.addActionListener(new ActionListener() {
        @Override/*from  w  w w  .  j  av  a  2 s . co  m*/
        public void actionPerformed(ActionEvent e) {
            Object item = sheetComboBox.getSelectedItem();
            if (item == null) {
                selectedSheetName = null;
            } else {
                selectedSheetName = sheetComboBox.getSelectedItem().toString();
            }
            updateUsingSelected();
        }
    });
    spinnerModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            updateUsingSelected();
        }
    });

    GuiUtil.setVisibleRowCount(dataPreviewTable, DEFAULT_VISIBLE_ROWCOUNT);

    Box top = Box.createHorizontalBox();
    top.add(new JLabel("Select Sheet: "));
    top.add(sheetComboBox);
    top.add(Box.createHorizontalGlue());
    top.add(new JLabel("Preview:"));
    top.add(new JSpinner(spinnerModel));
    top.add(Box.createHorizontalGlue());
    top.add(new JButton(useAction));
    //        if (more != null) {
    //            for (Component c : more) {
    //                top.add(c);
    //            }
    //        }

    add(top, BorderLayout.NORTH);
    add(dataPreviewScrollPane, BorderLayout.CENTER);

    useAction.setEnabled(false);
}

From source file:PizzaGridBagLayout.java

public PizzaGridBagLayout() {
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridBagLayout());
    addItem(panel1, new JLabel("Name:"), 0, 0, 1, 1, GridBagConstraints.EAST);
    addItem(panel1, new JLabel("Phone:"), 0, 1, 1, 1, GridBagConstraints.EAST);
    addItem(panel1, new JLabel("Address:"), 0, 2, 1, 1, GridBagConstraints.EAST);

    addItem(panel1, name, 1, 0, 2, 1, GridBagConstraints.WEST);
    addItem(panel1, phone, 1, 1, 1, 1, GridBagConstraints.WEST);
    addItem(panel1, address, 1, 2, 2, 1, GridBagConstraints.WEST);

    Box sizeBox = Box.createVerticalBox();
    ButtonGroup sizeGroup = new ButtonGroup();
    sizeGroup.add(small);/*w  w  w  .  j  a v a  2 s  .co m*/
    sizeGroup.add(medium);
    sizeGroup.add(large);
    sizeBox.add(small);
    sizeBox.add(medium);
    sizeBox.add(large);
    sizeBox.setBorder(BorderFactory.createTitledBorder("Size"));
    addItem(panel1, sizeBox, 0, 3, 1, 1, GridBagConstraints.NORTH);

    Box styleBox = Box.createVerticalBox();

    ButtonGroup styleGroup = new ButtonGroup();
    styleGroup.add(thin);
    styleGroup.add(thick);
    styleBox.add(thin);
    styleBox.add(thick);
    styleBox.setBorder(BorderFactory.

            createTitledBorder("Style"));
    addItem(panel1, styleBox, 1, 3, 1, 1, GridBagConstraints.NORTH);

    Box topBox = Box.createVerticalBox();
    ButtonGroup topGroup = new ButtonGroup();
    topGroup.add(pepperoni);
    topGroup.add(mushrooms);
    topGroup.add(anchovies);
    topBox.add(pepperoni);
    topBox.add(mushrooms);
    topBox.add(anchovies);
    topBox.setBorder(BorderFactory.createTitledBorder("Toppings"));
    addItem(panel1, topBox, 2, 3, 1, 1, GridBagConstraints.NORTH);

    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(okButton);
    buttonBox.add(Box.createHorizontalStrut(20));
    buttonBox.add(closeButton);
    addItem(panel1, buttonBox, 2, 4, 1, 1, GridBagConstraints.NORTH);

    this.add(panel1);
    this.pack();
    this.setVisible(true);
}

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);/* www .  j  ava  2 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, 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.stanwood.swing.AboutDialog.java

public void init() {
    Box box = Box.createVerticalBox();
    if (icon == null) {
        createTitleArea(box, title, version);
    } else {//from   w ww  .  ja v  a2s  .c  om
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(40));
        hbox.add(new JLabel(icon));
        hbox.add(Box.createHorizontalStrut(10));
        box.add(hbox);
        Box vbox = Box.createVerticalBox();
        createTitleArea(vbox, title, version);
        hbox.add(vbox);
        hbox.add(Box.createHorizontalGlue());
    }

    JTabbedPane infoTabbedPane = new JTabbedPane();
    infoTabbedPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JComponent tabAbout = createAboutTab();
    infoTabbedPane.addTab("About", tabAbout);
    JComponent tabAuthors = createAuthorsTab();
    infoTabbedPane.addTab("Authors", tabAuthors);
    box.add(infoTabbedPane);
    createButtonPane(box);

    setContentPane(box);
    setSize(450, 280);
    setLocationRelativeTo(getParent());
}

From source file:RGBAColourChooser.java

/**
 * Constructs a new RGBAColourChooser/* w ww .  java 2 s  . c  o  m*/
 */
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:com.diversityarrays.kdxplore.curate.fieldview.OverviewDialog.java

@SuppressWarnings("unchecked")
public OverviewDialog(Window window, String title,

        @SuppressWarnings("rawtypes") ComboBoxModel comboBoxModel, CurationData curationData,
        Transformer<TraitInstance, String> tiNameProvider, OverviewInfoProvider overviewInfoProvider,
        FieldViewSelectionModel fvsm, FieldLayoutTableModel fltm, CurationTableModel ctm) {
    super(window, title, ModalityType.MODELESS);

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    setAlwaysOnTop(true);/*from w ww  . j  a va2s.  c  o  m*/

    this.fieldViewSelectionModel = fvsm;

    @SuppressWarnings({ "rawtypes" })
    JComboBox activeTiCombo = new JComboBox(comboBoxModel);
    TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer(
            curationData.getTraitColorProvider(), tiNameProvider);
    activeTiCombo.setRenderer(tiCellRenderer);

    JLabel infoLabel = new JLabel(" ");
    infoLabel.setBorder(new BevelBorder(BevelBorder.LOWERED));

    final JFrame[] helpDialog = new JFrame[1];
    Action helpAction = new AbstractAction("?") {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (helpDialog[0] != null) {
                GuiUtil.restoreFrame(helpDialog[0]);
            } else {
                JFrame f = new JFrame("Overview Help");
                helpDialog[0] = f;
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setAlwaysOnTop(true);
                f.setLocationRelativeTo(overview);
                String html = Overview.getOverviewHelpHtml();
                JLabel label = new JLabel(html);
                label.setBorder(new EmptyBorder(0, 10, 0, 10));
                f.setContentPane(label);
                f.pack();
                f.setVisible(true);
            }
        }
    };

    //        Window window = GuiUtil.getOwnerWindow(FieldLayoutViewPanel.this);
    if (window != null) {
        if (window instanceof JFrame) {
            System.out.println("Found window: " + ((JFrame) window).getTitle());
        }
        window.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                window.removeWindowListener(this);
                if (helpDialog[0] != null) {
                    helpDialog[0].dispose();
                }
            }
        });
    }

    KDClientUtils.initAction(ImageId.HELP_24, helpAction, "Help for Overview");
    Box top = Box.createHorizontalBox();
    top.add(activeTiCombo);
    top.add(new JButton(helpAction));

    overview = new Overview(overviewInfoProvider, fltm, curationData, ctm, infoLabel);
    overview.setActiveTraitInstance(fvsm.getActiveTraitInstance(true));
    Container cp = getContentPane();

    cp.add(top, BorderLayout.NORTH);
    //      cp.add(traitLabel, BorderLayout.NORTH);
    cp.add(infoLabel, BorderLayout.SOUTH);
    cp.add(overview, BorderLayout.CENTER);

    pack();
    //      setResizable(false);

    //      setLocationRelativeTo(showOverviewButton);
    // DEFAULT POSITION is "out of the way"
    setVisible(true);

    this.fieldViewSelectionModel.addListSelectionListener(listSelectionListener);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            toFront();
        }

        @Override
        public void windowClosed(WindowEvent e) {
            fieldViewSelectionModel.removeListSelectionListener(listSelectionListener);
            removeWindowListener(this);
        }
    });
}

From source file:com.diversityarrays.kdxplore.field.CollectionPathSetupDialog.java

public CollectionPathSetupDialog(Window owner, String title, boolean wantPlotsPerGroup) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(useAction));

    Container cp = getContentPane();
    if (wantPlotsPerGroup) {
        plotsPerGroupChoice.addItemListener(new ItemListener() {
            @Override/*from w w w  .j a v  a 2  s . c o m*/
            public void itemStateChanged(ItemEvent e) {
                plotsPerGroup = (PlotsPerGroup) plotsPerGroupChoice.getSelectedItem();
            }
        });

        JPanel ppgPanel = new JPanel();
        GBH gbh = new GBH(ppgPanel);
        int y = 0;
        gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.EAST, "Plots Per Group:");
        gbh.add(1, y, 1, 1, GBH.HORZ, 1, 1, GBH.WEST, plotsPerGroupChoice);
        ++y;
        cp.add(ppgPanel, BorderLayout.NORTH);
    }

    cp.add(odtChoicePanel, BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);

    pack();
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExportDialog.java

public TraitExportDialog(Window owner, List<Trait> traits) {
    super(owner, "Export Traits", ModalityType.APPLICATION_MODAL);

    this.traits = traits;
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setGlassPane(backgroundRunner.getBlockingPane());

    JPanel mainPanel = new JPanel();
    GBH gbh = new GBH(mainPanel, 2, 1, 2, 1);
    int y = 0;/*  w ww  .j a  va 2  s .c om*/
    gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.EAST, "CSV file:");
    gbh.add(1, y, 1, 1, GBH.HORZ, 2, 1, GBH.CENTER, filepathField);
    gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(browseAction));
    ++y;

    exportAction.setEnabled(false);
    filepathField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateExportAction();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateExportAction();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateExportAction();
        }

        private void updateExportAction() {
            exportAction.setEnabled(!Check.isEmpty(filepathField.getText().trim()));
        }
    });
    File outdir = KdxplorePreferences.getInstance().getOutputDirectory();
    if (outdir != null) {
        File outfile = new File(outdir, "traits.csv");
        filepathField.setText(outfile.getPath());
    }

    Box buttons = Box.createHorizontalBox();
    buttons.add(openAfterExport);
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(exportAction));

    Container cp = getContentPane();
    cp.add(mainPanel, BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);
    pack();

    Dimension sz = getSize();
    setSize(600, sz.height);
}

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);
    }/*  www . j  a va2 s  . 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);
}