File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes handling jradiobuttonmenuitem select only once Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "handling jradiobuttonmenuitem select only once" Watch "handling jradiobuttonmenuitem select only once" New topic

handling jradiobuttonmenuitem select only once

Mark Lybarger
Ranch Hand

Joined: Dec 19, 2003
Posts: 72
i'm fairly new to swing, coming from jee.

i have a group of jradiobuttonmenuitem (s). when i select one, the actionPerformed method is always getting called. how do i only call the actionPerformed when it's first selcted.? right now i'm controling it by disabling the selected item, but that doesn't seem ideal.

Greg Brannon

Joined: Oct 24, 2010
Posts: 563
By design (and thankfully consistently), the actionPerformed() method will be called each time the menu item is selected. What the actionPerformed method DOES when called is under your program's control. What you're trying to do is not completely clear, but you could restrict what the actionPerformed() method does by determining if the menu item is already selected by using the isSelected() method and acting accordingly, OR if you mean that the menu item is only to be selected once, then it seems appropriate that it WOULD be disabled after being selected once. There are many other possibilities, but what I've suggested should suffice until you more completely describe what you're trying to do.

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you might be better off using an ItemListener

also, does it need to be static?
I agree. Here's the link:
subject: handling jradiobuttonmenuitem select only once
jQuery in Action, 3rd edition