Add four buttons to Box Layout - Java Swing

Java examples for Swing:BoxLayout

Description

Add four buttons to Box Layout

Demo Code

import java.awt.FlowLayout;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class Main extends JFrame {
  public Main() {
    super("Stacker");
    setSize(430, 150);/* w  w w .ja v a 2s  .  co m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create top panel
    JPanel commandPane = new JPanel();
    BoxLayout horizontal = new BoxLayout(commandPane, BoxLayout.X_AXIS);
    commandPane.setLayout(horizontal);
    JButton subscribe = new JButton("Subscribe");
    JButton unsubscribe = new JButton("Unsubscribe");
    JButton refresh = new JButton("Refresh");
    JButton save = new JButton("Save");
    commandPane.add(subscribe);
    commandPane.add(unsubscribe);
    commandPane.add(refresh);
    commandPane.add(save);
    // create bottom panel
    JPanel textPane = new JPanel();
    JTextArea text = new JTextArea(4, 70);
    JScrollPane scrollPane = new JScrollPane(text);
    // put them together
    FlowLayout flow = new FlowLayout();
    setLayout(flow);
    add(commandPane);
    add(scrollPane);
    setVisible(true);
  }

  public static void main(String[] arguments) {
    Main st = new Main();
  }
}

Related Tutorials