Example usage for javax.swing BoxLayout BoxLayout

List of usage examples for javax.swing BoxLayout BoxLayout

Introduction

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

Prototype

@ConstructorProperties({ "target", "axis" })
public BoxLayout(Container target, int axis) 

Source Link

Document

Creates a layout manager that will lay out components along the given axis.

Usage

From source file:Main.java

public Main() {
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    setSize(300, 400);/*  w ww  .  ja  v  a  2 s. co m*/
    getContentPane().add(panel, BorderLayout.EAST);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    loadLabel();
}

From source file:Main.java

public TabPanel() {
    JPanel innerPanel = new JPanel();
    innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.Y_AXIS));
    int USER_INPUT = 10;
    for (int i = 0; i < USER_INPUT; i++) {
        JPanel p = new JPanel(new BorderLayout());
        JLabel label = new JLabel("Label" + i);
        JTextField textArea = new JTextField();
        p.add(label, BorderLayout.NORTH);
        p.add(textArea, BorderLayout.CENTER);
        innerPanel.add(p);//from  w w w  .  ja  v  a2  s .c o m
    }

    JScrollPane scrollPane = new JScrollPane(innerPanel);
    scrollPane.setPreferredSize(new Dimension(400, 200));
    this.add(scrollPane);
}

From source file:layout.BoxLayoutDemo.java

public static void addComponentsToPane(Container pane) {
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

    addAButton("Button 1", pane);
    addAButton("Button 2", pane);
    addAButton("Button 3", pane);
    addAButton("Long-Named Button 4", pane);
    addAButton("5", pane);
}

From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java

public ColorPreferences(Component parent) {
    _parent = parent;/*from  w ww  . ja v a2 s . co m*/
    setBorder(new EmptyBorder(10, 10, 10, 10));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel pickers = new JPanel();
    pickers.setLayout(new GridLayout(10, 2));

    pickers.add(new Label(Messages.t("preferences.color.scheme.current.label")));
    _comboBox = createSchemeCombobox();
    pickers.add(_comboBox);

    addColorChooser(pickers, "gates");
    addColorChooser(pickers, "background");
    addColorChooser(pickers, "bus-on");
    addColorChooser(pickers, "ground");
    addColorChooser(pickers, "off");
    addColorChooser(pickers, "wires-on");
    addColorChooser(pickers, "signal");
    addColorChooser(pickers, "grid");
    addColorChooser(pickers, "label");
    add(pickers);

    JPanel buttons = new JPanel();
    JButton button = new JButton(Messages.t("preferences.color.scheme.save.label"));
    buttons.add(button);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    button = new JButton(Messages.t("preferences.color.scheme.new.label"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), "");
            if (themeName != null) {
                while (ColorScheme.exists(themeName)) {
                    JOptionPane.showMessageDialog(_parent,
                            Messages.t("color.scheme.dialog.already.exists.error"), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    themeName = JOptionPane.showInputDialog(this, themeName);
                }
                ColorScheme.add(themeName);
                _comboBox.addItem(themeName);
                _comboBox.setSelectedItem(themeName);
            }
        }
    });
    buttons.add(button);
    add(buttons);
}

From source file:SysConfig.java

public SysConfig() {
    super("JTabbedPane & BoxLayout Demonstration");
    setSize(500, 300);// w w  w.j  av a  2 s .  co m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JPanel configPane = new JPanel();
    configPane.setLayout(new BoxLayout(configPane, BoxLayout.Y_AXIS));
    JTextArea question = new JTextArea("Which of the following options\n" + "do you have installed?");
    // Ok, now configure the textarea to show up properly inside the box.
    // This is part of the "high art" of Swing...
    question.setEditable(false);
    question.setMaximumSize(new Dimension(300, 50));
    question.setAlignmentX(0.0f);
    question.setBackground(configPane.getBackground());

    JCheckBox audioCB = new JCheckBox("Sound Card", true);
    JCheckBox nicCB = new JCheckBox("Ethernet Card", true);
    JCheckBox tvCB = new JCheckBox("Video Out", false);

    configPane.add(Box.createVerticalGlue());
    configPane.add(question);
    configPane.add(audioCB);
    configPane.add(nicCB);
    configPane.add(tvCB);
    configPane.add(Box.createVerticalGlue());

    JLabel audioPane = new JLabel("Audio stuff");
    JLabel nicPane = new JLabel("Networking stuff");
    JLabel tvPane = new JLabel("Video stuff");
    JLabel helpPane = new JLabel("Help information");

    audioCB.addItemListener(new TabManager(audioPane));
    nicCB.addItemListener(new TabManager(nicPane));
    tvCB.addItemListener(new TabManager(tvPane));

    config.addTab("System", null, configPane, "Choose Installed Options");
    config.addTab("Audio", null, audioPane, "Audio system configuration");
    config.addTab("Networking", null, nicPane, "Networking configuration");
    config.addTab("Video", null, tvPane, "Video system configuration");
    config.addTab("Help", null, helpPane, "How Do I...");

    getContentPane().add(config, BorderLayout.CENTER);
}

From source file:Main.java

/** Make a JPanel with a horizontal {@link BoxLayout}. */
public static JPanel makeHorizontalBoxPanel() {
    JPanel result = new JPanel();
    result.setLayout(new BoxLayout(result, BoxLayout.X_AXIS));
    return result;
}

From source file:CardLayoutDemo.java

public void addCardsToPane(Container pane) {
    JRadioButton[] rb = new JRadioButton[strings.length];
    ButtonGroup group = new ButtonGroup();
    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.PAGE_AXIS));

    for (int i = 0; i < strings.length; i++) {
        rb[i] = new JRadioButton("Show component #" + (i + 1));
        rb[i].setActionCommand(String.valueOf(i));
        rb[i].addActionListener(this);
        group.add(rb[i]);//from   ww  w . ja  v a2s.  c  om
        buttons.add(rb[i]);
    }
    rb[0].setSelected(true);

    //Create the panel that contains the "cards".
    cards = new JPanel(new CardLayout());
    for (int i = 0; i < strings.length; i++) {
        cards.add(createComponent(strings[i]), String.valueOf(i));
    }

    pane.add(buttons, BorderLayout.NORTH);
    pane.add(cards, BorderLayout.CENTER);
}

From source file:QandE.Layout3.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./*from  w  w  w  . j a v a 2  s .com*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Layout3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add the innards.
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    p.add(createComponent("Component 1"));
    p.add(Box.createVerticalGlue());
    p.add(createComponent("Component 2"));
    p.add(createComponent("Component 3"));
    p.add(createComponent("Component 4"));
    frame.setContentPane(p);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    super("Demostrating BoxLayout");
    final int SIZE = 3;
    Container c = getContentPane();
    c.setLayout(new BorderLayout(30, 30));

    Box boxes[] = new Box[4];

    boxes[0] = Box.createHorizontalBox();
    boxes[1] = Box.createVerticalBox();
    boxes[2] = Box.createHorizontalBox();
    boxes[3] = Box.createVerticalBox();

    for (int i = 0; i < SIZE; i++)
        boxes[0].add(new JButton("boxes[0]: " + i));

    for (int i = 0; i < SIZE; i++) {
        boxes[1].add(Box.createVerticalStrut(25));
        boxes[1].add(new JButton("boxes[1]: " + i));
    }//w  w w  .j  ava  2 s.com

    for (int i = 0; i < SIZE; i++) {
        boxes[2].add(Box.createHorizontalGlue());
        boxes[2].add(new JButton("boxes[2]: " + i));
    }

    for (int i = 0; i < SIZE; i++) {
        boxes[3].add(Box.createRigidArea(new Dimension(12, 8)));
        boxes[3].add(new JButton("boxes[3]: " + i));
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    for (int i = 0; i < SIZE; i++) {
        panel.add(Box.createGlue());
        panel.add(new JButton("panel: " + i));
    }

    c.add(boxes[0], BorderLayout.NORTH);
    c.add(boxes[1], BorderLayout.EAST);
    c.add(boxes[2], BorderLayout.SOUTH);
    c.add(boxes[3], BorderLayout.WEST);
    c.add(panel, BorderLayout.CENTER);

    setSize(350, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);

}

From source file:MemComboBoxDemo.java

public MemComboBoxDemo() {
    super();//  ww w.  j  av  a  2 s.  com
    setSize(300, 100);
    getContentPane().setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(new JLabel("Address"));

    urlComboBox.load("addresses.dat");
    ComboBoxListener lst = new ComboBoxListener();
    urlComboBox.addActionListener(lst);

    MemComboAgent agent = new MemComboAgent(urlComboBox);

    p.add(urlComboBox);
    getContentPane().add(p, BorderLayout.NORTH);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            urlComboBox.save("addresses.dat");
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
    urlComboBox.grabFocus();
}