Beans在 NetBeans 中绑定 JTable

发布于 2024-07-27 17:09:33 字数 536 浏览 4 评论 0原文

我想将 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 技术交流群。

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

发布评论

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

评论(3

尐籹人 2024-08-03 17:09:33

我有它的工作。 您不能真正使用 JTables 的“Bind”菜单选项。 下面是让它工作的方法:

  1. 右键单击​​ JTable。
  2. 单击“表内容”。
    1. 绑定来源:表单
    2. 绑定表达式:${var}(其中 var 是 beans 列表的名称)。
  3. 单击“列”选项卡。
  4. 将列映射到表达式。 它应该看起来像 ${id} 而不是 ${var.id}。

注意:映射到列的每个字段都必须有一个 getter。

I have it working. You can't really use the "Bind" menu option for JTables. Here's how to get it to work:

  1. Right-Click the JTable.
  2. Click "Table Contents".
    1. Binding Source: Form
    2. Binding expression: ${var} (where var is the name of the list of beans).
  3. Click the "Columns" tab.
  4. Map the column to the expression. It should look something like ${id} not ${var.id}.

Note: Each field mapped to a column must have a getter.

深海少女心 2024-08-03 17:09:33

尽管使用 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.

虐人心 2024-08-03 17:09:33

尝试使该列表成为可观察的列表。 将其初始化更改为如下所示:

list1 = ObservableCollections.observableList(new ArrayList<Person>());

然后很多员工应该开始工作。 如果要绑定到 bean,请确保在要绑定的属性的 set 方法中触发属性更改事件,添加此代码

private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

public void addPropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(listener);
}

修复导入,然后执行类似以下操作

public void setFirstName(String firstName) {
    String oldFirstName = this.firstName;
    this.firstName = firstName;
    changeSupport.firePropertyChange("firstName", oldFirstName, firstName);
}

Try making the list an observable one. change its initialization to something like this:

list1 = ObservableCollections.observableList(new ArrayList<Person>());

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

private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

public void addPropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.addPropertyChangeListener(listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener) {
    changeSupport.removePropertyChangeListener(listener);
}

fix imports and then do something like this

public void setFirstName(String firstName) {
    String oldFirstName = this.firstName;
    this.firstName = firstName;
    changeSupport.firePropertyChange("firstName", oldFirstName, firstName);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文