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.开发者_如何学Go
I am performing the below steps to perform this in Netbeans:
- Right click on
tf
>> Properties >> Binding - Click on button
...
at the right ofenabled
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.
精彩评论