无法将文本字段绑定到 NetBeans 中 JTable 中的选定项目
我正在尝试使用 NetBeans 将 JTextField 绑定到 JTable 的选定元素。
JTable 从返回 Cow 对象的 AbstractTableModel 子类获取数据。目前,每个 Cow 对象都通过其 toString 方法显示为 String。
我试图将 JTextField 的 text 属性绑定到 JTable 中选择的 Cow 对象的 name 属性。
我将 NetBeans 中 JTextField 的文本属性绑定到:
flowTable[${selectedElement.name}]
这将生成以下生成代码行:
org.jdesktop.beansbinding.Binding binding =
org.jdesktop.beansbinding.Bindings.createAutoBinding(
org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
cowTable,
org.jdesktop.beansbinding.ELProperty.create("${selectedElement.name}"),
cowNameTextField,
org.jdesktop.beansbinding.BeanProperty.create("text"));
文本字段的绑定值始终为 null。
我做错了什么?
I am trying to use NetBeans to bind a JTextField to the selected element of a JTable.
The JTable gets its data from an AbstractTableModel subclass which returns Cow objects. At present, each Cow object is displayed as a String through its toString method.
I am trying to bind the text property of the JTextField to the name property of the Cow object which is selected in the JTable.
I bound the text property of the JTextField in NetBeans to:
flowTable[${selectedElement.name}]
This produces the following line of generated code:
org.jdesktop.beansbinding.Binding binding =
org.jdesktop.beansbinding.Bindings.createAutoBinding(
org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
cowTable,
org.jdesktop.beansbinding.ELProperty.create("${selectedElement.name}"),
cowNameTextField,
org.jdesktop.beansbinding.BeanProperty.create("text"));
The bound value of the text field is always null.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的
Cow
类是否有一个public String getName()
方法返回名称?如果没有,您得到的结果就是预期的。如果是这样,您可以发布更多代码(您的数据类、表模型、表...)。
Does your
Cow
class have apublic String getName()
method returning the name?If it doesn't, the outcome you're getting would be expected. If it does, could you post more code (your data class, tablemodel, table...).
如果您只对表中的 String 感兴趣,而不是 Cow 对象本身:
If you only are interested in a String in the table, and not the Cow object itself:
您的 Cow 类支持添加
PropertyChangeListener
吗?我不经常使用 NetBeans 的 Bean 绑定支持,但我记得您需要它。无论如何,更多的代码可以帮助找出问题所在。Does your Cow class support adding a
PropertyChangeListener
? I did not use the beans binding support from NetBeans that often, but I remember you needed it. Anyway, a little more code could help with finding out whats going wrong.