groovy swingbuilder 可绑定列表和表格
有没有办法使用 groovy swing 构建器绑定语法将数据绑定到列表和/或表?我只能找到将字符串和数字等简单属性绑定到文本字段、标签或按钮文本的简单示例。
Is there a way to bind data to a list and/or a table using the groovy swing builder bind syntax? I could only find simple examples that bind simple properties like strings and numbers to a text field, label, or button text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
环顾四周,我能看到的最好的结果是使用 GlazedLists 而不是标准 Swing 列表
http:// /www.jroller.com/aalmiray/entry/glazedlists_groovy_not_your_regular
Had a look round, and the best I could see was using GlazedLists rather than standard Swing lists
http://www.jroller.com/aalmiray/entry/glazedlists_groovy_not_your_regular
有一个 GlazedList 插件。 这篇文章非常有帮助。狮鹫们对 GlazedLists 非常信赖。
There is a GlazedList plugin. And this article is very helpful. The Griffon guys swear by GlazedLists.
我只是做了这样的事情——手动做起来确实不难。这仍然是一项正在进行的工作,但如果它对任何人有帮助,我可以提供我所拥有的。到目前为止,它在两个方向上绑定数据(更新数据更新组件,编辑表更新数据并向“行”的任何 propertyChangeListener 发送通知)
我使用一个类来定义表的一行。您创建此类来定义表的性质。它看起来像这样:
请注意,一旦将其余代码打包到一个类中,这个“Row”类就是创建新表时唯一需要创建的东西。您为每一行创建此类的实例,将它们添加到表中,然后就完全完成了——除了将表放入框架之外,没有其他 gui 工作。
这个类可以包含更多的代码——我打算让它包含一个轮询数据库并更新绑定属性的线程,然后表应该立即获取更改。
为了提供自定义列属性,我定义了一个如下所示的注释(我计划添加更多):
其余的是构建表的类。我将它保存在一个单独的类中,以便可以重用它(通过使用不同的“Row”类实例化它)
注意:我在粘贴它时将其删除,因此如果不做一点工作它可能无法运行(可能是大括号)。它曾经包含一个框架,我将其删除以仅包含桌子。您需要将从 getTable() 返回的表包装在框架中。
可能有一种方法可以通过公开可绑定列表来做到这一点,而无需添加/删除,但这似乎需要更多工作,但没有太多好处。
在某个时候,我可能会把完成的课程放在某个地方——如果您已经读到这里并且仍然感兴趣,请回复评论,我一定会尽快这样做。
I just did something like this--it's really not that hard to do manually. It's still a work in progress, but if it helps anyone I can give what I have. So far it binds the data in both directions (Updating the data updates the component, editing the table updates the data and sends a notification to any propertyChangeListeners of the "Row")
I used a class to define one row of a table. You create this class to define the nature of your table. It looks something like this:
Note that once the rest of the code is packaged up in a class, this "Row" class is the ONLY thing that needs to be created to create a new table. You create instances of this class for each row, add them to the table and you are completely done--no other gui work aside from getting the table into a frame.
This class could include quite a bit more code--I intend to have it contain a thread that polls a database and updates the bound properties, then the table should pick up the changes instantly.
In order to provide custom column properties I defined an annotation that looks like this (I plan to add more):
The rest is a class that builds the table. I keep it in a separate class so it can be reused (by instantiating it with a different "Row" class)
NOTE: I butchered this as I pasted it in so it may not run without a little work (braces probably). It used to include a frame which I removed to just include the table. You need to wrap the table returned from getTable() in a frame..
There is probably a way to do this without the add/remove by exposing a bindable list but it seemed like more work without a lot of benifit.
At some point I'll probably put the finished class up somewhere--if you have read this far and are still interested, reply in a comment and I'll be sure to do it sooner rather than later.