• Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckbox  RSS feed

 
kate damond
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • 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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • 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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Glen Tanner
Ranch Hand
Posts: 147
Java Python Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I lied. The Manning book IS in the bunkhouse. It just hasn't been reviewed yet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!