2011-12-30 54 views
3

我試圖將JLabel的可見性綁定到JTextField的文本是否爲空。Java綁定bean到字符串空屬性

我想這樣做,因爲我想隱藏JLabel紅色星號,這表示在文本字段填充是強制性的,所以它應隱藏當它被填充。

然而,下列情況不工作(與$ {text.isEmpty}):

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
      org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, 
      estimatedCostTextField, 
      org.jdesktop.beansbinding.ELProperty.create("${text.isEmpty}"), 
      estimatedCostAsterisk, 
      org.jdesktop.beansbinding.BeanProperty.create("visible")); 

bindingGroup.addBinding(binding); 

有人能幫助我嗎?

回答

0

我找到了答案。您應該使用${empty text}

因此,代碼變爲:

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
      org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, 
      estimatedCostTextField, 
      org.jdesktop.beansbinding.ELProperty.create("${empty text}"), 
      estimatedCostAsterisk, 
      org.jdesktop.beansbinding.BeanProperty.create("visible")); 

bindingGroup.addBinding(binding);