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:BoxLayoutGlueStrutCompare.java

public BoxLayoutGlueStrutCompare() {
    JPanel p = new JPanel(new GridLayout(3, 1));

    JPanel p1 = new JPanel();
    Box box1 = new Box(BoxLayout.X_AXIS);
    box1.add(Box.createHorizontalGlue());
    box1.add(new JButton("glue-strut"));
    box1.add(Box.createHorizontalStrut(15));
    box1.add(new JButton("strut-glue"));
    box1.add(Box.createHorizontalGlue());
    p1.add(box1);/* w  w  w  .ja  v  a2s .co  m*/
    p1.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p2 = new JPanel();
    Box box2 = new Box(BoxLayout.X_AXIS);
    box2.add(Box.createHorizontalStrut(25));
    box2.add(new JButton("strut-glue"));
    box2.add(Box.createHorizontalGlue());
    box2.add(new JButton("glue-strut"));
    box2.add(Box.createHorizontalStrut(25));
    p2.add(box2);
    p2.setBorder(BorderFactory.createRaisedBevelBorder());

    JPanel p3 = new JPanel();
    Box box3 = new Box(BoxLayout.X_AXIS);
    box3.add(Box.createHorizontalStrut(25));
    box3.add(new JButton("strut-glue"));
    box3.add(Box.createHorizontalGlue());
    box3.add(new JButton("glue-glue"));
    box3.add(Box.createHorizontalGlue());
    p3.add(box3);
    p3.setBorder(BorderFactory.createRaisedBevelBorder());

    p.add(p1);
    p.add(p2);
    p.add(p3);
    getContentPane().add(p);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
}

From source file:Main.java

public Main() {
    super(BoxLayout.Y_AXIS);

    Box info = Box.createVerticalBox();
    info.add(new Label("Please wait 3 seconds"));
    final JButton continueButton = new JButton("Continue");
    info.add(continueButton);/*from   w  w  w  . j  a v a  2  s  .co  m*/

    JDialog d = new JDialog();
    d.setModalityType(ModalityType.APPLICATION_MODAL);
    d.setContentPane(info);
    d.pack();

    continueButton.addActionListener(e -> d.dispose());
    continueButton.setVisible(false);

    SwingWorker sw = new SwingWorker<Integer, Integer>() {
        protected Integer doInBackground() throws Exception {
            int i = 0;
            while (i++ < 30) {
                System.out.println(i);
                Thread.sleep(100);
            }
            return null;
        }

        @Override
        protected void done() {
            continueButton.setVisible(true);
        }

    };
    JButton button = new JButton("Click Me");
    button.addActionListener(e -> {
        sw.execute();
        d.setVisible(true);
    });
    add(button);
}

From source file:Main.java

public Main() {
    JFormattedTextField formattedField = null;
    try {//from w  w w  .  j  a v a  2 s . c  o  m
        MaskFormatter dateMask = new MaskFormatter("##/##/####");
        formattedField = new JFormattedTextField(dateMask);
    } catch (ParseException ex) {
        System.out.println(ex);
    }
    formattedField.setColumns(10);
    formattedField.setInputVerifier(getInputVerifier());

    JTextField field = new JTextField(10);
    format.setLenient(false);

    Box box = Box.createVerticalBox();
    box.add(formattedField);
    box.add(Box.createVerticalStrut(10));
    box.add(field);
    box.setBorder(new EmptyBorder(10, 10, 10, 10));

    JFrame frame = new JFrame();
    frame.add(box);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:Main.java

private Box getEditPaneBox() {
    editorPane.setEditable(false);/* ww  w  . j  ava 2 s  . c om*/
    Box editorBox = Box.createHorizontalBox();
    editorBox.add(new JScrollPane(editorPane));

    editorPane.addHyperlinkListener((HyperlinkEvent event) -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            go(event.getURL());
        } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) {
            System.out.println("click this link");
        } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) {
            System.out.println("Ready");
        }
    });

    editorPane.addPropertyChangeListener((PropertyChangeEvent e) -> {
        String propertyName = e.getPropertyName();
        if (propertyName.equalsIgnoreCase("page")) {
            URL url = editorPane.getPage();
            System.out.println(url.toExternalForm());
        }
    });

    return editorBox;
}

From source file:Main.java

public Main() {
    Box box1 = Box.createVerticalBox();
    for (int i = 1; i <= 100; i++) {
        box1.add(new JLabel("This is Label #" + i));
    }//from   w w w .j av a  2  s  . co  m

    Box box2 = Box.createVerticalBox();
    for (int i = 1; i <= 100; i++) {
        box2.add(new JLabel("This is Label #" + i));
    }

    JPanel boxPanel1 = new JPanel();
    JPanel boxPanel2 = new JPanel();
    boxPanel1.add(box1);
    boxPanel2.add(box2);
    JScrollPane panel1Scroll = new JScrollPane(boxPanel1);
    JScrollPane panel2Scroll = new JScrollPane(boxPanel2);

    panelTab1 = new JPanel(new BorderLayout());
    panelTab2 = new JPanel(new BorderLayout());
    panelTab1.add(panel1Scroll);
    panelTab2.add(panel2Scroll);

    tabbedPane = new JTabbedPane();
    tabbedPane.add(panelTab1, "Panel 1");
    tabbedPane.add(panelTab2, "Panel 2");

    JFrame frame = new JFrame();
    frame.add(tabbedPane);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:layout.BoxLayoutDemo2.java

public void populateContentPane(Container contentPane) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    //Create the rectangles.
    int shortSideSize = 15;
    for (int i = 0; i < NUM_COMPONENTS; i++) {
        if (sizeIsRandom) {
            shortSideSize = (int) (30.0 * Math.random()) + 30;
        } else {//  w w w  .  java  2  s  . c  o m
            shortSideSize += 10;
        }
        bldComponent[i] = new BLDComponent(xAlignment[i], hue[i], shortSideSize, restrictSize, sizeIsRandom,
                String.valueOf(i));
        panel.add(bldComponent[i]);
    }

    //Create the instructions.
    JLabel label = new JLabel("Click a rectangle to " + "change its X alignment.");
    JCheckBox cb = new JCheckBox("Restrict maximum rectangle size.");
    cb.setSelected(restrictSize);
    cb.addItemListener(this);

    panel.setBorder(BorderFactory.createLineBorder(Color.red));

    Box box = Box.createVerticalBox();
    box.add(label);
    box.add(cb);

    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(box, BorderLayout.PAGE_END);
}

From source file:Main.java

public Main() {
    Box box = Box.createHorizontalBox();
    box.setBorder(new EmptyBorder(5, 5, 5, 5));
    Dimension size = new Dimension(100, 25);

    box.add(createButton("Button1", size));
    box.add(createStrut());//from w  w  w  . j  av a  2  s  .co  m
    box.add(createButton("Button2", size));
    box.add(createStrut());
    box.add(createButton("Button3", size));
    box.add(createStrut());
    box.add(createButton("Button4", size));

    add(box);
}

From source file:Main.java

public Main() {
    Box box = new Box(BoxLayout.Y_AXIS);
    add(box);/*from w w w  . j a v a 2s . c o  m*/

    JLabel label = new JLabel("I'm centered");
    label.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    box.add(Box.createVerticalGlue());
    box.add(label);
    box.add(Box.createVerticalGlue());
}

From source file:HBoxWithStrut.java

public HBoxWithStrut() {
    super("Box & Strut Frame");
    setSize(370, 80);/*from  www .ja  v a2s  .c o m*/
    Box box = Box.createHorizontalBox();
    setContentPane(box);
    for (int i = 0; i < 3; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }

    // Add a spacer between the first three buttons and the last three
    box.add(Box.createHorizontalStrut(10));
    for (int i = 3; i < 6; i++) {
        Button b = new Button("B" + i);
        box.add(b);
    }
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:Main.java

public Main() {

    for (int i = 0; i < 15; i++) {
        ((DefaultListModel<String>) sourceList.getModel()).add(i, "A " + i);
        ((DefaultListModel<String>) destList.getModel()).add(i, "B " + i);
    }/*from  ww w . j a va 2  s . co m*/
    Box nameBox = Box.createHorizontalBox();
    nameBox.add(new JLabel("New:"));
    nameBox.add(newTextField);

    Box sourceBox = Box.createVerticalBox();
    sourceBox.add(new JLabel("Source"));
    sourceBox.add(new JScrollPane(sourceList));

    Box destBox = Box.createVerticalBox();
    destBox.add(new JLabel("Destination"));
    destBox.add(new JScrollPane(destList));

    Box listBox = Box.createHorizontalBox();
    listBox.add(sourceBox);
    listBox.add(destBox);

    Box allBox = Box.createVerticalBox();
    allBox.add(nameBox);
    allBox.add(listBox);

    this.getContentPane().add(allBox, BorderLayout.CENTER);

    sourceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    destList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    newTextField.setDragEnabled(true);
    sourceList.setDragEnabled(true);
    destList.setDragEnabled(true);

    sourceList.setDropMode(DropMode.INSERT);
    destList.setDropMode(DropMode.INSERT);

    sourceList.setTransferHandler(new ListTransferHandler());
    destList.setTransferHandler(new ListTransferHandler());
}