Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

handling jradiobuttonmenuitem select only once

 
Mark Lybarger
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might be better off using an ItemListener


also, does it need to be static?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic