Results 1 to 8 of 8
- 12-29-2008, 03:46 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
JCheckBox button - what wrong with me..
Hi everyone
I'm new in Java and swing, and the GUI concept ,, but I'm learning
I tried implemnt some radio - and event if I select or diselct it ( write TCSH on or off.. ) . but the problem - when ever the mouse is just getting - I get dozen of meseges "TCSH on" or off . what wrong with me ?
Java Code:checkTCSH.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (checkErr.isSelected()) { System.out.println("TCSH ON"); state_TCSH=1; } else{ System.out.println("TCSH OFF"); state_TCSH=1; } /* end of if */} /* end of statechange*/ } /*end of changelistener*/ );
-
Only your doctor and/or girlfriend can answer that, but as for your code...what wrong with me ?
It's unusual to use a ChangeListener with a button as it detects changes of all the states of the button including (as you're finding out) rollover. It would be far better to use an ActionListener here, something that responds to the button being clicked.
- 12-30-2008, 03:24 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you are new to Java Swing, it's better look at some examples first of all. Tutorial on Suns' website is really great.
- 12-30-2008, 11:01 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
- 12-30-2008, 03:17 PM #5
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
It is not solved yet... :confused:
well , I tried to change the ChangeListener to ActionListener as detail in the code below
but .. it just do the select option and not the de-select option
checkTCSH is a CheckBox button
Java Code:checkTCSH.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (checkErr.isSelected()) { System.out.println("TCSH ON"); state_TCSH=1; } else{ System.out.println("TCSH OFF"); state_TCSH=0; } /* end of if */ } } /*end of changelistener*/ );
- 12-30-2008, 03:25 PM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Its bit confusing, you are adding listener to checkTCSH , but you are checking the state of checkErr, what is your exact requirement?
- 12-30-2008, 03:26 PM #7
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
My error - thanks , it works nowyou are adding listener to checkTCSH , but you are checking the state of checkErr, what is your exact requirement?
- 12-30-2008, 04:09 PM #8
Similar Threads
-
Regarding JTree with JCheckBox and JRadioButton
By partha_adt in forum AWT / SwingReplies: 0Last Post: 11-11-2008, 10:03 AM -
Issue with Jcheckbox on JTableheader
By ram_76uk in forum AWT / SwingReplies: 2Last Post: 07-30-2008, 08:24 AM -
Can we add JCheckBox array into JTextArea?
By nancyhung in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 12:07 AM -
jcheckbox issues need help. thanks.
By carlos123 in forum New To JavaReplies: 3Last Post: 11-05-2007, 10:37 PM -
using JCheckBox, JButton and JTextArea with JDBC
By warship in forum JDBCReplies: 1Last Post: 08-08-2007, 01:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks