• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ChangeListener stateChanged Question

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a ChangeListener attached to a JRadioButton. The documentation is not clear (to me) on what events trigger the 'stateChanged' method. Based on the method name and what I gathered from the documentation, it should only trigger when the radio button is clicked. Apparently that is not the case. It seems to also be triggered when it gets focus and perhaps other events, unknown to me at this point. So my question is, how do I determine in 'stateChanged' specifically that the state changed? TIA.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javax.swing.event.ChangeListener is vague on purpose, because what constitutes the state of an object is very broad. I can't find anything in the documentation that would make me think it only triggers when the button is clicked. Focus, size and whether the component is enabled are also part of the component's state.

To get notified when a button is clicked by a user, you need to use java.awt.event.ActionListener.

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I guess it was the name of the method that made me think it was sensible to use it for an on/off type component.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

made me think it was sensible to use it for an on/off type component



You have been given a link to the Swing tutorial before for this exact reason.

The tutorial shows you the basics of how to use each component.

Read the tutorial and download the examples to learn the basics.

The API does not provide as much information as a working example can provide.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You misunderstand and incorrectly assume. It was not a question of HOW to use but rather WHEN. The examples did not clearly indicate what triggers a stateChanged event.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but rather WHEN.  



And that is my point. If you look at the tutorial on radio buttons you will see that none of the examples use a ChangeListener.

So the question is why are you trying to do this? What problem are you trying to solve? First you need to learn the basics.

Then when the basics don't solve your problem you ask a question with a specific requirement.

There is no documentation for every situation that will cause a ChangeEvent to be generated. If you need to know then you need to learn how to answer the question yourself. The way you do this is to look at the source code and do a search for everywhere a ChangeEvent is generated.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic