List of usage examples for javax.swing JButton JButton
public JButton(Action a)
Action
supplied. From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component = new JButton("a"); Set<AWTKeyStroke> set = new HashSet<AWTKeyStroke>( component.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); set.add(KeyStroke.getKeyStroke("F2")); component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Text Button"); button1.setMnemonic(KeyEvent.VK_B); frame.add(button1);/*from w ww. j a v a 2 s. co m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Button"); frame.add(button);// w w w. ja va 2 s .c o m frame.setAlwaysOnTop(true); frame.setSize(500, 500); frame.setLocation(500, 500); button.addActionListener(e -> { JOptionPane optionPane = new JOptionPane("Option Pane"); optionPane.showMessageDialog(frame, "Message!"); }); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String s = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>" + "<font color=\"#FF0080\"><u>Multi-line</u></font>"; JButton button = new JButton(s); JOptionPane.showMessageDialog(null, button); }
From source file:Main.java
public static void main(String[] args) { JButton button = new JButton("ok"); button.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { DefaultButtonModel model = (DefaultButtonModel) button.getModel(); if (model.isEnabled()) System.out.println("Enabled: true"); else/*from w ww .j av a2 s . co m*/ System.out.println("Enabled: false"); if (model.isArmed()) System.out.println("Armed: true"); else System.out.println("Armed: false"); if (model.isPressed()) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); } }); JOptionPane.showMessageDialog(null, button); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }/* w ww. j a va 2 s . c om*/ }); jb.doClick(1000); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }//from ww w . j a va2 s . c o m }); jb.doClick(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }/* w ww .j a v a 2 s . co m*/ }); System.out.println(jb.getActionCommand()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); }// www .j a v a 2s . c om }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:ButtonFocus.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton focusButton = new JButton("Focused"); JButton notFocusButton = new JButton("Not Focused"); frame.setLayout(new FlowLayout()); frame.add(focusButton);//from w ww . j ava2 s . c om frame.add(notFocusButton); frame.setSize(300, 100); frame.setVisible(true); }