aspose file tools*
The moose likes Beginning Java and the fly likes enable checkbox question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enable checkbox question" Watch "enable checkbox question" New topic
Author

enable checkbox question

Vonique Leary
Ranch Hand

Joined: Mar 24, 2008
Posts: 107
In my beginning Java Programming workbook there is an example of toggling between setting the checkbox enabled or disabled, but I'm not quite sure I get it. The instructor couldn't really explain it to me except to say that it is toggling because of the ! operator:



Can anyone explain this to me? What does the !checkbox.isEnabled() method return to checkbox.setEnabled that does the opposite of what is is now?

Thanks, Vonuu
Frankey James
Ranch Hand

Joined: Sep 27, 2008
Posts: 50
checkbox.isEnabled // returns a bool of true of false.

checkbox.setEnabled() //requires a bool to determine if the checkbox should be enabled or not

!checkbox.isEnabled means to inverse (or toggle) the CURRENT value of checkbox.isEnabled by negating the current value witht he ! operator

So checkbox.setEnabled(!checkbox.isEnabled()); so this is changing the current state (enabled or not) to the opposite of what it currenlt is

more lines of code example could look like this:

//disable checkbox if it's enabled, and enable it if it's currently not enabled
if(checkbox.isEnabled == true){

checkbox.setEnabled(false);

}else if(checkbox.isEnabled == flase){

checkbox.setEnabled(true);
}


Make cents?


ho, ho, ho
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Good explanation (barring the dreadful pun in the last line), but never use == true or == false. They are prone to nasty errors if you manage to write = instead of ==.

If you use the CODE button as you ought, you get:I think Vonique's original example more elegant.
Vonique Leary
Ranch Hand

Joined: Mar 24, 2008
Posts: 107
Thanks, yes that makes a lot of cents to me now! I like the pun, too.

Great explanation!

Von
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Vonique Leary wrote:I like the pun, too.
Aaaargh!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enable checkbox question
 
Similar Threads
Adding checkbox to some selected row of a column.
click one checkbox will submit only one checkbox value (not the whole form) immediately
Need Help with binding click events to table rows
Checking whether check boxes are checked
retreiving all rows from a mysql table to a jsp page