简体   繁体   中英

Java Swing - How to bind a JComponent in Netbeans?

I am using Netbeans Swing GUI builder to design my app's GUI. I have a JTextField tf and a JCheckBox cb .

Now, I want that the tf is enabled only when the cb is both enabled and selected.

I am performing the below steps to perform this in Netbeans:

  1. Right click on tf >> Properties >> Binding
  2. Click on button ... at the right of enabled
  3. Binding Source: tf

    Binding Expression: ${selected}

Now, in the above steps, binding expression can be set either to ${selected} or to ${enabled} .

But according to my needs, the binding expression should be something like ${selected} && ${enabled} .

I tried the above expression too but it didn't work.

How can I do that through Netbeans?

The expression you want is,

${enabled && selected}

Type the expression manually into the field.

You must do one additional thing. Go to the Advanced tab, and change the Update Mode from Read/write to Read-Only . Otherwise, the disablement of the text field will also disable the checkbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM