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.TrialLayoutEditorDialog.java

public TrialLayoutEditorDialog(Window owner, String title) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    trialLayoutEditPanel = new TrialLayoutEditPanel(onLayoutComplete);

    saveAction.setEnabled(false);//from ww w .  ja v a 2s. co  m
    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(saveAction));

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

    pack();
}

From source file:BoxLayoutTest.java

public Box createBox(boolean horizontal, boolean strutsAndGlue) {
    Box b;
    if (horizontal)
        b = Box.createHorizontalBox();
    else//from   w w w.j a  va  2  s  .  c  o m
        b = Box.createVerticalBox();

    b.add(new JLabel("Name: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        if (horizontal)
            b.add(Box.createHorizontalStrut(5));
        else
            b.add(Box.createVerticalStrut(5));

    b.add(new JLabel("Password: "));
    b.add(new JTextField());

    if (strutsAndGlue)
        b.add(Box.createGlue());

    b.add(new JButton("Ok"));

    return b;
}

From source file:UndoableToggleApp4.java

public UndoableToggleApp4() {
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from  w  ww .  ja v a  2s . co m
    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:RasterDemo.java

public RasterDemo() {
    super();//from  ww w.  ja  v  a 2 s. c  o  m
    Container container = getContentPane();

    displayPanel = new RasterPanel();
    container.add(displayPanel);

    Box box = Box.createHorizontalBox();
    flipButton = new JToggleButton("Flip the Image");
    flipButton.addActionListener(new ButtonListener());
    box.add(Box.createHorizontalGlue());
    box.add(flipButton);
    box.add(Box.createHorizontalGlue());
    container.add(box, BorderLayout.SOUTH);

    addWindowListener(new WindowEventHandler());
    setSize(450, 400);
    show();
}

From source file:UndoableToggleApp3.java

public UndoableToggleApp3() {

    // Create some toggle buttons.
    UndoableJToggleButton tog1 = new UndoableJToggleButton("One");
    UndoableJToggleButton tog2 = new UndoableJToggleButton("Two");
    UndoableJToggleButton tog3 = new UndoableJToggleButton("Three");

    // Add our listener to each toggle button.
    SimpleUEListener sl = new SimpleUEListener();
    tog1.addUndoableEditListener(sl);//from   w w  w  .jav  a  2s.  com
    tog2.addUndoableEditListener(sl);
    tog3.addUndoableEditListener(sl);

    // Lay out the buttons.
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog1);
    buttonBox.add(tog2);
    buttonBox.add(tog3);

    // Create undo and redo buttons (initially disabled).
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

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

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

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

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

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 www.j  av a 2  s  .  c  om*/
    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:org.stanwood.swing.AboutDialog.java

private void createButtonPane(Box box) {
    Box hBox = Box.createHorizontalBox();
    hBox.add(Box.createHorizontalGlue());
    JButton cmdClose = new JButton(StandardActions.getDialogCloseAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            cancel();/*from  ww  w . j  a va 2s  .  co m*/
        }
    }));
    hBox.add(cmdClose);
    box.add(hBox);

    hBox.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));

    cmdClose.requestFocusInWindow();
}

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

/** Builds a SeriesAttributes with the provided generator, name for the series, and index for the series.  Calls
 buildAttributes to construct custom elements in the LabelledList, then finally calls rebuildGraphicsDefinitions()
 to update the series. *//*from   w  w w .j  ava 2 s.  c om*/
public SeriesAttributes(ChartGenerator generator, String name, int index, SeriesChangeListener stoppable) {
    super(name);
    setStoppable(stoppable);
    this.generator = generator;
    seriesIndex = index;
    final JCheckBox check = new JCheckBox();
    check.setSelected(true);
    check.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setPlotVisible(check.isSelected());
        }
    });

    manipulators = new Box(BoxLayout.X_AXIS);
    buildManipulators();
    JLabel spacer = new JLabel("");
    spacer.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    Box b = new Box(BoxLayout.X_AXIS);
    b.add(check);
    b.add(spacer);
    b.add(manipulators);
    b.add(Box.createGlue());
    addLabelled("Show", b);

    final PropertyField nameF = new PropertyField(name) {
        public String newValue(String newValue) {
            SeriesAttributes.this.setSeriesName(newValue);
            rebuildGraphicsDefinitions();
            return newValue;
        }
    };
    addLabelled("Series", nameF);

    buildAttributes();
    rebuildGraphicsDefinitions();
}

From source file:com.diversityarrays.kdxplore.heatmap.HeatMapParamsDialog.java

public HeatMapParamsDialog(VisualisationTool vtool, CurationContext ctx,
        //         PlotInfoProvider pip,
        SelectedValueStore svs, Map<TraitInstance, SimpleStatistics<?>> numericStatsByTraitInstance,
        Map<JFrame, HeatMapPanelParameters> heatMapPanelParamsByFrame, VisToolOpenClose vtoc,
        SuppressionHandler suppressionHandler) {
    super(ctx.getDialogOwnerWindow(), Msg.TOOLNAME_HEATMAP(), ModalityType.MODELESS);

    this.suppressionHandler = suppressionHandler;
    this.visualisationTool = vtool;
    this.context = ctx;
    this.selectedValueStore = svs;
    //      this.plotInfoProvider = pip;
    this.heatMapPanelParamsByFrame = heatMapPanelParamsByFrame;
    this.visToolOpenClose = vtoc;

    //      this.heatMapFrameByPane = new HashMap<JFrame, HeatMapPane>();

    List<ValueRetriever<?>> positionAndPlotRetrievers = new ArrayList<>();
    Trial trial = context.getTrial();/*w w  w.jav  a  2 s  . c o m*/
    positionAndPlotRetrievers.addAll(ValueRetrieverFactory.getPlotIdentValueRetrievers(trial));

    Map<PlotAttribute, Set<String>> attributesAndValues = context.getPlotAttributesAndValues();

    for (PlotAttribute pa : attributesAndValues.keySet()) {
        positionAndPlotRetrievers.add(new PlotAttributeValueRetriever(pa, attributesAndValues.get(pa)));
    }

    pnatPanel = new AskForPositionNamesAndTraitInstancePanel(2, // positionNames 
            1, // traitInstances
            positionAndPlotRetrievers, numericStatsByTraitInstance, enableActionNotifier, context);

    createHeatMapAction.setEnabled(false);

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

    getContentPane().add(pnatPanel, BorderLayout.CENTER);
    getContentPane().add(buttons, BorderLayout.SOUTH);

    pack();
}

From source file:org.cytoscape.dyn.internal.graphMetrics.SaveChartDialog.java

public SaveChartDialog(JFrame frame, JFreeChart chart) {
    super(frame, "Save Chart to File", false);
    this.chart = chart;
    JPanel sizePanel = new JPanel(new GridLayout(2, 3, 4, 4));
    sizePanel.setBorder(BorderFactory.createTitledBorder("Image Size"));

    // Add a spinner for choosing width
    sizePanel.add(new JLabel("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("pixels"));

    // Add a spinner for choosing height
    sizePanel.add(new JLabel("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("pixels"));

    JPanel buttonsPanel = new JPanel(new GridLayout(1, 2, 4, 0));
    saveChartButton = new JButton("Save");
    saveChartButton.setMaximumSize(new Dimension(Short.MAX_VALUE, saveChartButton.getHeight()));
    saveChartButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.setMaximumSize(new Dimension(Short.MAX_VALUE, cancelButton.getHeight()));
    cancelButton.addActionListener(this);
    buttonsPanel.add(saveChartButton);//from   w w w .j  a  v a 2s.co  m
    buttonsPanel.add(cancelButton);
    Box buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(Box.createHorizontalGlue());
    buttonsBox.add(buttonsPanel);
    buttonsBox.add(Box.createHorizontalGlue());

    Container contentPane = getContentPane();
    contentPane.add(sizePanel, BorderLayout.NORTH);
    contentPane.add(Box.createVerticalStrut(3));
    contentPane.add(buttonsBox, BorderLayout.PAGE_END);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    getRootPane().setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    pack();
    setModal(true);
    setResizable(false);
    setLocationRelativeTo(frame);

}