I have a check button and I was wondering how to get the value from it. When I use this code it gives me that it is selected always, even when it is not.

public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub
		JCheckBox sourceBox = ((JCheckBox)e.getSource());
		wave1Invert = wave1Inv.get ();
		wave2Invert = wave2Inv.isSelected ();
		if (wave1Inv == sourceBox){
			
			if (wave1Invert = true){
				System.out.println ("Wave 1 Inv");
			}
			else if (wave1Invert = false){
				System.out.println ("Wave 1 NOT Inv");
			}
		}
			
		if (wave2Inv == sourceBox){
			if (wave2Invert = true){
				System.out.println ("Wave 2 Inv");
			}
			else if (wave2Invert = false){
				System.out.println ("Wave 2 NOT Inv");
			}
		}
	}

Thanks for your help

Recommended Answers

All 2 Replies

Check your equality tests. == is equality, = is assignment

Thanks that fixed the problem. Though I thought that to compare booleans you just use =, but I guess I was wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.