Example usage for javax.swing JButton JButton

List of usage examples for javax.swing JButton JButton

Introduction

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

Prototype

public JButton(Action a) 

Source Link

Document

Creates a button where properties are taken from the Action supplied.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);//from   w  ww .  j  a va 2  s  .c  o m

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.BOTTOM_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);/*from   w  w  w . j  ava2s  . c  o  m*/

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.LEFT_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);/*  ww w.  j a va 2 s .co  m*/

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.TOP_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);//from  w  ww. ja  v a  2 s  .  c  o m

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);/* ww w  .  j  a v  a  2 s . com*/

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.RIGHT_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:RootExample.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JRootPane root = f.getRootPane(); // XXX Pay attention to these
    Container content = root.getContentPane(); // XXX lines. They get more
    content.add(new JButton("Hello")); // XXX explanation in the book.
    f.pack();/*from  w  w  w  . j  a  va 2  s  . co m*/
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    final String LABEL_FACTORY = "LabelFactory";

    JFrame frame = new JFrame("Active Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    UIManager.put(LABEL_FACTORY, new ActiveLabel());

    final JPanel panel = new JPanel();

    JButton button = new JButton("Get");

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JLabel label = (JLabel) UIManager.get(LABEL_FACTORY);
            panel.add(label);/*  ww  w.  j a  v  a 2s.com*/
            panel.revalidate();
        }
    };
    button.addActionListener(actionListener);

    frame.add(panel, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(200, 200);
    frame.setVisible(true);
}

From source file:ButtonModelTesting.java

public static void main(String args[]) {
    JFrame f = new JFrame("Button Model Tester");
    JButton jb1 = new JButton("Hello");
    ButtonModel bm = jb1.getModel();
    JButton jb2 = new JButton("World");
    jb2.setModel(bm);/*  w w  w.j ava 2 s.  c o m*/
    Container c = f.getContentPane();
    c.add(jb1, BorderLayout.NORTH);
    c.add(jb2, BorderLayout.SOUTH);
    jb1.addActionListener(new MessageActionListener("Selected One"));
    jb2.addActionListener(new MessageActionListener("Selected Two"));
    f.pack();
    f.show();
}

From source file:Main.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    layout.layoutContainer(container);/*from  ww  w . ja va2 s  .  co m*/
    container.setLayout(layout);

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("My Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border border = new BlackWhiteBorder();
    JButton helloButton = new JButton("Hello");
    helloButton.setBorder(border);/*  w  ww. ja  va2s  .  co  m*/
    JButton braveButton = new JButton("Brave New");
    braveButton.setBorder(border);
    braveButton.setEnabled(false);
    JButton worldButton = new JButton("World");
    worldButton.setBorder(border);
    Container contentPane = frame.getContentPane();
    contentPane.add(helloButton, BorderLayout.NORTH);
    contentPane.add(braveButton, BorderLayout.CENTER);
    contentPane.add(worldButton, BorderLayout.SOUTH);
    frame.setSize(300, 100);
    frame.setVisible(true);
}