• 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

JCheckbox

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have this JCheck box, and have called its addChangeListener method. This works fine : the change listener sets the text in some other textFields to default values. This works whenever JCheckbox gets clicked.
Alas, it also works when the users mouse enters JCheckbox without clicking anything ... just when the mouse passes over the area.
Is it supposed to do this ?
Kate
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kate:


A subscribed ChangeListner would be notified wheh the button is
armed, pressed, selected, or released. It is also notified of changes to the ButtonModel such as for the keyboard mnemonic (keyevent).


You probably should not use addChangeListner( ).
If you want to get notified when the user toggles the state of the JCheckBox, you need to use an ActionListner instead.
regds.
- satya
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try
yourChkBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
someMethodThatDoesWhatYouWant();
}
});

It will only execute when it is clicked.
 
kate damond
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's great - the item listener works great. Now, if I hadn't had you guys to ask - how should I have gone about finding that out ? I use the documentation at java.sun.com, but find it really unhelpful on listeners (evidently !)
Kate
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats why you need to visit our Bunkhouse (selfishly
promoting the bunkhouse) and select one of the many
books after reading some great reviews....
http://www.javaranch.com/books.jsp

regds.
- satya
 
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kate,
There's a free Swing book here. Take a look at Chapter 2 "Swing Mechanics". (especially the section on "Event Handling and Dispatching").
Don't tell anyone I told though, 'cause this book ain't in the bunkhouse.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Don't tell anyone I told though, 'cause this book ain't in the bunkhouse.

Yup, we just ran out of stock esp. after our recent
free book giveaway...
- satya
 
Glen Tanner
Ranch Hand
Posts: 147
Android Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I lied. The Manning book IS in the bunkhouse. It just hasn't been reviewed yet.
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic