Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look at JRadioButton.<a href="http://docs.oracle.com/javase/6/docs/api/javax/swing/AbstractButton.html#addItemListener%28java.awt.event.ItemListener%29" rel="nofollow noreferrer">addItemListener</a>()</p> <p>EDIT: It is unlikely you want to use a changeListener as it fires multiple times per click. An itemListener fires only once per click. <a href="https://web.archive.org/web/20140718235540/http://www.herongyang.com/Swing/jradio.html" rel="nofollow noreferrer">See here</a></p> <p>EDIT2: Just to expand on this, an actionListener on a jradioButton will fire every time a user clicks on it, even if it is already selected. if that's what you want, fine, but I find it annoying. I only want to be notified it it is selected or deselected.</p> <p>A ChangeListener will fire for all sorts of things, meaning your listener will receive 5 or more events per click. Not good.</p> <p>An itemlistener will fire <em>only</em> if the selected or deselected state changes. This means that a user can click on it multiple times and it will not fire if it doesn't change. In your handler method you will have to have an <code>if</code> block checking for <code>SELECTED</code> or <code>DESELECTED</code> status and do whatever there:</p> <pre><code>@Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // Your selected code here. } else if (e.getStateChange() == ItemEvent.DESELECTED) { // Your deselected code here. } } </code></pre> <p>It just works better because you know that if you are in the method then the radio button has either just been selected or deselected, not that the user is just banging on the interface for some unknown reason. </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