Beans在 NetBeans 中绑定 JTable
我想将 bean 列表映射到 JTable。 这个想法是,每一列将是 bean 中的预选字段,每一行将是列表中的一个 bean。 这里的幻灯片 #32 看起来非常有前途:http://swinglabs。 org/docs/presentations/2007/DesktopMatters/beans-binding-talk.pdf
但是,NetBeans 不太友好地让我将 bean 字段分配给列。 我可以右键单击 JTable 并单击 Bind->Elements 并将其绑定到我的 bean 列表。 但是,它不会让我指定每列中的内容。 唯一的选择是自己创建绑定,这几乎使 NetBeans 对于此类事情毫无用处。
我有遗漏的细节吗? NetBeans 中的 JTable BeansBinding 似乎已损坏。
谢谢
I want map a List of beans to a JTable. The idea is that each column will be a preselected field in the bean and each row will be a bean in the List. Slide #32 here looks very promising: http://swinglabs.org/docs/presentations/2007/DesktopMatters/beans-binding-talk.pdf
However, NetBeans is not very friendly in letting me assign a bean field to a column. I can right-click the JTable and click Bind->Elements and bind it to my List of beans. However, it will not let me specify what goes in each column. The only option is to create the binding myself which pretty much makes NetBeans useless for this type of thing.
Is there a detail I'm missing? It appears that JTable BeansBinding in NetBeans is just broken.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有它的工作。 您不能真正使用 JTables 的“Bind”菜单选项。 下面是让它工作的方法:
注意:映射到列的每个字段都必须有一个 getter。
I have it working. You can't really use the "Bind" menu option for JTables. Here's how to get it to work:
Note: Each field mapped to a column must have a getter.
尽管使用 IDE 来完成这类事情可能很有吸引力,但实际上没有什么可以替代自己编写代码。
就我个人而言,我更喜欢 Glazed Lists 在表格中呈现 bean。 花 2 分钟观看视频,我保证您会被迷住的。 只需不到 15 行代码,您就可以获得所需的内容,并对显示进行大量控制 - 加上过滤、排序和所有其他很酷的东西(当您准备好时)。
As appealing as it may be to use the IDE for this sort of stuff, there's really no substitute for just coding it yourself.
Personally, I prefer Glazed Lists for presenting beans in tables. Take the 2 minutes and watch the video, and I guarantee that you'll be hooked. With less than 15 lines of code, you'll get what you are looking for, and have a huge amount of control over the display - plus filtering, sorting and all sorts of other cool stuff when you are ready for it.
尝试使该列表成为可观察的列表。 将其初始化更改为如下所示:
然后很多员工应该开始工作。 如果要绑定到 bean,请确保在要绑定的属性的 set 方法中触发属性更改事件,添加此代码
修复导入,然后执行类似以下操作
Try making the list an observable one. change its initialization to something like this:
Then a lot of staff should start working. If you are binding to a bean then make sure you fire a property changed event in the set method of the property you want bound add this code
fix imports and then do something like this