Results 1 to 3 of 3
  1. #1
    DGates is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Post Enable/Disable Text Field upon checking check box

    Hi,
    Id like to create a situation where upon a check box being selected it enables a text box. As it stands I have used an ActionPerformed Event:
    Java Code:
    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
           boolean chkbox = jCheckBox1.isSelected();
            if (chkbox = true)
         {
       jTextField13.setEnabled(true);
    }
            else if (chkbox  = false){    //the code from here onwards does not seem to work.
       jTextField13.setEnabled(false); 
            }
        }
    When it is run the check box enables the associated Text Field but it does not disable it when unchecked again.
    Does anyone have any suggestions for how to get this to work?
    Thanks,
    DGates

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,748
    Rep Power
    19

    Default Re: Enable/Disable Text Field upon checking check box

    You want:
    Java Code:
    if (chkBox) {
    } else {
    }
    at the moment you are setting chkBox to true in the if everytime.
    Java Code:
       public static void main(String[] args) {
          boolean chkBox = false;
          if (chkBox = true) {
             System.out.println("Good lord I'm true!");
          }
       }
    Will print out everytime.

  3. #3
    DGates is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: Enable/Disable Text Field upon checking check box

    Thanks, alot.

Similar Threads

  1. How to Enable and Disable JtextField on Selection of Checkbox
    By deshmukh.niraj04 in forum New To Java
    Replies: 1
    Last Post: 04-11-2011, 12:26 PM
  2. Please help : JSP enable/disable button
    By kalyana in forum New To Java
    Replies: 3
    Last Post: 03-24-2011, 05:06 PM
  3. Checking if enter has been pressed on a text field
    By BoomPony in forum New To Java
    Replies: 1
    Last Post: 01-28-2011, 03:18 PM
  4. use javascript to enable/disable hyperlinks
    By sauravsinha in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 04-22-2010, 06:04 PM
  5. Replies: 2
    Last Post: 04-28-2008, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •