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

public static void main(String... args) {
    JFrame frame = new JFrame();
    JSpinner jspinner = makeDigitsOnlySpinnerUsingDocumentFilter();
    frame.getContentPane().add(jspinner, BorderLayout.CENTER);
    frame.getContentPane().add(new JButton("just another widget"), BorderLayout.SOUTH);
    frame.pack();/*from www  .  j a  va 2 s .  c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame fr = new JFrame();
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    String[] ss = new String[] { "112", "1223", "1124", "1134" };
    fr.getContentPane().add(p);/*from  ww w . java  2  s  .  co  m*/
    AutoCompleteComboBox cb = new AutoCompleteComboBox(ss);

    p.add("South", cb);
    p.add("Center", new JButton("test combo box"));
    fr.pack();
    fr.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField textField = new JTextField();
    label.setLabelFor(textField);//from   w ww  .  j  ava  2 s  .  c o  m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());

    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);

    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*from w w w .j  a va  2 s.com*/

    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:ImageBorderHack.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Hack #59: Image Border");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    JButton button = new JButton("Image Border Test");
    panel.add(button);/* www.  j av  a  2s.  c o m*/

    ImageBorder image_border = new ImageBorder(new ImageIcon("upperLeft.png").getImage(),
            new ImageIcon("upper.png").getImage(), new ImageIcon("upperRight.png").getImage(),

            new ImageIcon("leftCenter.png").getImage(), new ImageIcon("rightCenter.png").getImage(),

            new ImageIcon("bottomLeft.png").getImage(), new ImageIcon("bottomCenter.png").getImage(),
            new ImageIcon("bottomRight.png").getImage());
    panel.setBorder(image_border);

    frame.getContentPane().add(panel);
    frame.pack();
    // frame.setSize(200,200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("GroupLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    GroupLayout groupLayout = new GroupLayout(contentPane);
    groupLayout.setAutoCreateGaps(true);
    groupLayout.setAutoCreateContainerGaps(true);
    contentPane.setLayout(groupLayout);//from   www . j a v a 2s.  c  o  m

    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button Second");
    JButton b3 = new JButton("3");
    JButton b4 = new JButton("4");

    groupLayout.setHorizontalGroup(groupLayout.createSequentialGroup()
            .addGroup(groupLayout.createParallelGroup(LEADING).addComponent(b1).addComponent(b3))
            .addGroup(groupLayout.createParallelGroup(TRAILING).addComponent(b2).addComponent(b4)));

    groupLayout.setVerticalGroup(groupLayout.createSequentialGroup()
            .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b1).addComponent(b2))
            .addGroup(groupLayout.createParallelGroup(BASELINE).addComponent(b3).addComponent(b4)));

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String title = "GridBagLayout";
    JFrame frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();

    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 4; x++) {
            gbc.gridx = x;//from  w w w. java 2s.  c o m
            gbc.gridy = y;
            String text = "Button (" + x + ", " + y + ")";
            contentPane.add(new JButton(text), gbc);
        }
    }

    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    JPanel topPane = new JPanel();
    JPanel midPane = new JPanel();
    JPanel panesHolder = new JPanel();
    JLabel label = new JLabel("Top label");
    JTextField field = new JTextField();
    field.setColumns(5);/*from  w  w  w.  j a  va2 s.c  om*/

    topPane.setLayout(new FlowLayout());
    midPane.setLayout(new GridLayout(3, 2));

    topPane.add(label);
    topPane.add(field);

    midPane.add(new JButton("Button 1"));
    midPane.add(new JButton("Button 2"));
    midPane.add(new JButton("A"));
    midPane.add(new JButton("H"));
    midPane.add(new JButton("I"));
    midPane.add(new JButton("T"));

    panesHolder.setLayout(new BoxLayout(panesHolder, BoxLayout.Y_AXIS));
    panesHolder.add(topPane);
    panesHolder.add(midPane);

    frame.add(panesHolder);
    frame.setSize(400, 300);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

From source file:Main.java

public static void main(String[] arguments) {
    JPanel panel = new JPanel(new BorderLayout());
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);//from w  w  w  .  j  a va2s .com
    frame.setBounds(20, 20, 200, 200);
    frame.setVisible(true);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setVisible(false);
    JButton loadButton = new JButton("Load memberlist");
    loadButton.setEnabled(true);
    loadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    progressBar.setVisible(true);
                    // do my stuff here...
                    try {
                        Thread.sleep(2000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    progressBar.setVisible(false);
                }
            }).start();
        }
    });
    JPanel container = new JPanel(new FlowLayout());
    container.add(loadButton);
    container.add(progressBar);
    panel.add(container);
}

From source file:Main.java

public static void main(String[] args) {

    JPanel ui = new JPanel(new BorderLayout(2, 2));
    ui.setBorder(new EmptyBorder(4, 4, 4, 4));

    JPanel controls = new JPanel(new BorderLayout(2, 2));
    ui.add(controls, BorderLayout.PAGE_START);
    String s = new String(Character.toChars(8594));
    String[] items = { "Choice: right " + s + " arrow" };
    JComboBox cb = new JComboBox(items);
    controls.add(cb, BorderLayout.CENTER);
    controls.add(new JButton("Button"), BorderLayout.LINE_END);

    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JTextArea(4, 40), new JTextArea(4, 40));

    ui.add(sp, BorderLayout.CENTER);

    JFrame f = new JFrame("Stretch Combo Layout");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(ui);//from www  .  jav  a  2 s .c  o m
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}