Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

handling jradiobuttonmenuitem select only once

 
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.


 
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.
 
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?
 
BWA HA HA HA HA HA HA! Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic