Java 使用 BeanBinding Netbeans 更新 JList

发布于 2024-07-21 18:19:20 字数 630 浏览 2 评论 0原文

我在 JFrame 中有这个 JList(比如 MyList)。 我正在使用 Netbeans6 GUI 构建器,并且我已经为此列表设置了绑定。

运行时,绑定工作正常,并且 MyList 已正确填充。

现在,我正在寻找一种从单击按钮上的另一个文本框向此列表添加更多数据的方法。 但这里存在问题:

如果没有绑定,我将使用“getModel()”函数提取 JList 的 ListModel,并使用“addElement()”向其中添加元素。

但是,当我使用 Binding 时。 我尝试提取 ListModel 并将其映射到 DefaultListModel 我得到以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jdesktop.swingbinding.JListBinding$BindingListModel cannot be cast to javax.swing.DefaultListModel

所以我的问题是,如何向已绑定到其他数据源的 MyList 添加更多元素?

有人有任何线索吗? 任何帮助将不胜感激!

谢谢!

I have this JList (say MyList) in a JFrame. Im using Netbeans6 GUI builder and I've set a binding for this list.

When run, the binding works fine, and MyList is populated correctly.

Now, what im looking for is a way to add more data to this list from another text box on a button Click. But the problem exists here :

W/o binding i would extract the ListModel for the JList using "getModel()" function and add element to it using "addElement()".

However, when im using Binding. and i try to extract the ListModel and Map it to DefaultListModel i get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jdesktop.swingbinding.JListBinding$BindingListModel cannot be cast to javax.swing.DefaultListModel

So my question is , how do i add more elements to MyList which is already bound to some other dataSource ?

Anyone has any clues ?
Any Help will greatly appreciated!!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-07-28 18:19:20

您必须修改 JList 绑定到的列表。 并且这个列表必须是一个 Observable 列表才能注册变更。 绑定的要点是您不再操作组件的模型,而是操作它们的底层数据类型。

You have to modify the List to which the JList is bound. And this List must be an Observable list for the change to be registered. The point of binding is that you don't manipulate components' models anymore, but their underlaying data types instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文