JCheckBox not working properly when pressed

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 966 Views - Last Post: 12 July 2011 - 03:33 PM Rate Topic: ***** 2 Votes

#1 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

JCheckBox not working properly when pressed

Posted 12 July 2011 - 12:54 PM

Hello guys i just created a GUI for my application and this is first time its not working.. Well no errors in code just that nothing happends when the checkbox is pressed.. Here is what i wrote.

          if(CheckBox.isSelected()){ 
                    JComboBox1.setVisible(false);
		    JComboBox2.setVisible(false);
		    JComboBox3.setVisible(false);
                    JComboBox4.setVisible(false);
                    JComboBox5.setVisible(true);
                    JComboBox6.setVisible(true);
                    JComboBox7.setVisible(true);
                    JComboBox8.setVisible(true);
                    JComboBox9.setVisible(true);
                    JComboBox10.setVisible(true);
                    JComboBox11.setVisible(true);
                }


The thing is that JComboBox 5-11 is set visible to false when the GUI is started and when you press this they will become visible and the other ones will be not visible.. Is there anything i did wrong or why is this not working properly?

Is This A Good Question/Topic? 1
  • +

Replies To: JCheckBox not working properly when pressed

#2 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 12:59 PM

Did you add ChangeListener for CheckBox?
Was This Post Helpful? 1
  • +
  • -

#3 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:01 PM

No man.. Is that like the same to make action listener for button ?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:07 PM

Yes. Remember that GUI programming is event-driven, and you need Listeners to respond to events. As always, start with the documentation.
Was This Post Helpful? 0
  • +
  • -

#5 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:26 PM

        ChangeListener changeListener = new ChangeListener() {
            public void stateChanged(ChangeEvent changeEvent) {
               if(CheckBox.isSelected()){
	           JComboBox1.setVisible(false);
	           JComboBox2.setVisible(false);
	           JComboBox3.setVisible(false);
	           JComboBox4.setVisible(false);
	           JComboBox5.setVisible(true);
                   JComboBox6.setVisible(true);
                   JComboBox7.setVisible(true);
	           JComboBox8.setVisible(true);
	           JComboBox9.setVisible(true);
	           JComboBox10.setVisible(true);
	           JComboBox11.setVisible(true);
	      }
      }
    };


Thats what i did but still not working..
Was This Post Helpful? 1
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:27 PM

Remember you need to add it to the JCheckBox you want to listen to.
Was This Post Helpful? 0
  • +
  • -

#7 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:30 PM

Oh how would i do that ?
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:31 PM

Did you even read the documentation? I linked to it.
Was This Post Helpful? 0
  • +
  • -

#9 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:33 PM

Yes but i found nothing that i was looking for.. I have a hard time reading those documentation i am working on learning how to browse them and learning how to read em.
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:34 PM

The method is addChangeListener(). Seriously, read the documentation. If it doesn't say static, you know how to invoke a method on an object. The documentation is really self-explanatory.
Was This Post Helpful? 0
  • +
  • -

#11 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:37 PM

Sorry but i don't have much experience of reading the documentation its all new to me.
Was This Post Helpful? 0
  • +
  • -

#12 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:44 PM

Seems like we have some corrupt moderators here.
Was This Post Helpful? -5
  • +
  • -

#13 HarryBo123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-July 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:46 PM

Ohh I think I found it. Ohh wait no dw.
Was This Post Helpful? 0
  • +
  • -

#14 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:48 PM

You need to make like this for example CheckBox.addChangeListener(changelistener);
Was This Post Helpful? 0
  • +
  • -

#15 HarryBo123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-July 11

Re: JCheckBox not working properly when pressed

Posted 12 July 2011 - 01:54 PM

I find it funny I come onto this forum new looking for help and all my posts are being removed by this moderator.
Was This Post Helpful? -2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2