List of usage examples for javax.swing JButton JButton
public JButton(String text, Icon icon)
From source file:Main.java
public static void main(final String args[]) { Icon icon = new ImageIcon("dog.jpg"); JButton button = new JButton("Dog", icon); JOptionPane.showMessageDialog(null, button); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("DefaultButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon warnIcon = new ImageIcon("Warn.gif"); JButton button3 = new JButton("Warning", warnIcon); frame.add(button3);/* w w w. j av a 2 s.c o m*/ frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(""); Container contentPane = frame.getContentPane(); Icon icon = new PieIcon(Color.red); JButton b = new JButton("Button!", icon); contentPane.add(b, BorderLayout.NORTH); b = new JButton(icon); contentPane.add(b, BorderLayout.SOUTH); frame.setSize(300, 200);/*www. jav a 2 s. c om*/ frame.show(); }
From source file:Main.java
public static void main(String args[]) { ImageIcon iconA = new ImageIcon("IconA.gif"); ImageIcon iconDiable = new ImageIcon("disable.gif"); ImageIcon iconOver = new ImageIcon("over.gif"); ImageIcon iconPressed = new ImageIcon("IconAPressed.gif"); final JButton jbtnA = new JButton("Alpha", iconA); JFrame jfrm = new JFrame(); jfrm.setLayout(new FlowLayout()); jfrm.setSize(300, 300);/*from w w w . j a va 2s. co m*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jbtnA.setRolloverIcon(iconOver); jbtnA.setPressedIcon(iconPressed); jbtnA.setDisabledIcon(iconDiable); jfrm.getRootPane().setDefaultButton(jbtnA); jbtnA.setMnemonic(KeyEvent.VK_A); jbtnA.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Alpha pressed. Beta is enabled."); jbtnA.setEnabled(!jbtnA.isEnabled()); } }); jfrm.add(jbtnA); jfrm.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); Icon normalIcon = new TriangleIcon(Color.red, TriangleIcon.State.NORMAL); Icon pressedIcon = new TriangleIcon(Color.red, TriangleIcon.State.PRESSED); Icon rolloverIcon = new TriangleIcon(Color.red, TriangleIcon.State.ROLLOVER); JButton b = new JButton("Button", normalIcon); b.setPressedIcon(pressedIcon);//ww w. j a v a2s . c o m b.setRolloverIcon(rolloverIcon); b.setRolloverEnabled(true); contentPane.add(b, BorderLayout.NORTH); frame.setSize(300, 100); frame.show(); }