开发者

Java Swing - How to bind a JComponent in Netbeans?

开发者 https://www.devze.com 2022-12-28 07:22 出处:网络
I am using Netbeans Swing GUI builder to design my app\'s GUI. I have a JTextField tf and a JCheckBox cb.

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:

  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消