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

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setLayout(null);//from ww  w . j  a  v  a  2s  .c o  m

    JButton ok = new JButton("OK");
    ok.setBounds(50, 150, 80, 25);

    JButton close = new JButton("Close");
    close.setBounds(150, 150, 80, 25);

    f.add(ok);
    f.add(close);

    f.setSize(300, 250);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");
    System.out.println(jb.getHorizontalAlignment() == SwingConstants.LEFT);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);//www  .  j  a va 2  s .c  o  m
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Test");

    button.setHorizontalTextPosition(SwingConstants.LEFT);
    button.setIcon(new ImageIcon("r.gif"));
    button.setRolloverIcon(new ImageIcon("b.gif"));
    button.setRolloverEnabled(true);//from   ww  w  . ja v  a 2 s  .  c  om

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    pane.addTab("Tab Label", new JButton("Button"));
    // Get index of the new tab
    int index = pane.getTabCount() - 1;

    // Determine whether the tab is enabled
    boolean enabled = pane.isEnabledAt(index);

    // Disable the tab
    pane.setEnabledAt(index, false);//from w ww  .j a v  a  2  s .  c  om
}

From source file:PanelWithComponents.java

public static void main(String[] a) {
    JPanel panel = new JPanel();
    JButton okButton = new JButton("OK");
    panel.add(okButton);/*from w ww .jav  a 2  s .  c o  m*/
    JButton cancelButton = new JButton("Cancel");
    panel.add(cancelButton);
    JFrame frame = new JFrame("Oval Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Test");

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button pressed");
        }/*from  ww w . j a  va 2s .com*/
    });

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Test");

    button.addActionListener(new ClickListener());
    JOptionPane.showMessageDialog(null, button);

    button.doClick();/*  ww w .  j a v  a2 s .co  m*/
}

From source file:Main.java

public static void main(final String args[]) {
    String label = "<html>" + "This is a" + "<br>" + "swing button" + "</html>";

    JButton button = new JButton(label);

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(final String args[]) {
    JButton button = new JButton("Text Button");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            String command = actionEvent.getActionCommand();
            System.out.println("Selected: " + command);
        }/*from w  ww  .  j av  a2 s . c  o m*/
    };

    button.setActionCommand("First");
    button.addActionListener(actionListener);

    JOptionPane.showMessageDialog(null, button);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTabbedPane pane = new JTabbedPane();
    JButton component = new JButton("button");

    String tooltip = "Tool Tip Text";
    pane.addTab("label", new ImageIcon("icon.png"), component, tooltip);

}