Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JToggleButton.html"><code>JToggleButton</code></a>. More specifically, use the <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setIcon%28javax.swing.Icon%29"><code>setIcon</code></a> and <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/AbstractButton.html#setSelectedIcon%28javax.swing.Icon%29"><code>setSelectedIcon</code></a> methods. Using this approach, you'll avoid reinventing the wheel.</p> <p><strong>EXAMPLE -</strong></p> <pre><code>import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JToggleButton; import javax.swing.SwingUtilities; import javax.swing.UIManager; final class JToggleButtonDemo { public static final void main(final String[] args) { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { createAndShowGUI(); } }); } private static final void createAndShowGUI(){ final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout()); // For presentation purposes only. final JToggleButton button = new JToggleButton(UIManager.getIcon("OptionPane.informationIcon")); button.setSelectedIcon(UIManager.getIcon("OptionPane.errorIcon")); frame.add(button); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } } </code></pre> <p>The toggle button in this example will show an information icon when unselected and an error icon when selected.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload