List of usage examples for javax.swing JButton setModel
@BeanProperty(description = "Model that the Button uses.") public void setModel(ButtonModel newModel)
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); 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();/*from w w w .java 2 s . co m*/ f.show(); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame(); JButton jb1 = new JButton("Hello"); ButtonModel bm = jb1.getModel(); JButton jb2 = new JButton("World"); jb2.setModel(bm); 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();// w w w . j a va2 s. c om f.show(); }
From source file:Main.java
public static void main(String[] args) { final JButton ok = new JButton("ok"); JCheckBox cb = new JCheckBox("Enabled", true); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (ok.isEnabled()) ok.setEnabled(false);/*from w ww . j a va 2 s. c o m*/ else ok.setEnabled(true); } }); ButtonModel model = new DefaultButtonModel() { public void setEnabled(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setEnabled(b); } public void setArmed(boolean b) { if (b) System.out.println("Armed: true"); else System.out.println("Armed: false"); super.setArmed(b); } public void setPressed(boolean b) { if (b) System.out.println("Pressed: true"); else System.out.println("Pressed: false"); super.setPressed(b); } }; ok.setModel(model); JFrame f = new JFrame(); f.setLayout(new FlowLayout()); f.add(ok); f.add(cb); f.setSize(350, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }