根据另一个ComboBox选项更改ComboBox中的ItemList [英] Change ItemList in a ComboBox depending from another ComboBox choice

查看:159
本文介绍了根据另一个ComboBox选项更改ComboBox中的ItemList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我必须道歉,因为英语不是我的母语,但我会尽力明白我的要求。



我有一套在tableview中,每行的每行都有不同的组合框。因此,组合框之间的相互作用必须是每行。如果在Combobox A1中,我选择项目1,在Combobox A2中将更新项目列表。
我的问题是每个组合框A2,B2,C2等都是根据A1中的选择进行更新...与B1,C1组合框相同。根据A1,我需要更新A2。 B2根据B1等等。



我通过cellfactory设置组合框,因为我必须将数据从后面保存在可序列化的对象中。



希望是明确的。



问候。

解决方案

这真是一个痛苦...



TableCell ,您可以观察到 TableRow 通过它的 tableRowProperty()



来自 TableRow ,您可以通过表格行的 itemProperty()来观察行中的项目。



当然,从行中的项目中,您可以观察模型类中定义的任何属性,并相应地更新组合框中的项目列表。



痛苦的部分是这些价值中的任何一个都可以,并且在某些时候会发生变化。因此,您需要观察的事情不断变化,您必须在发生这种情况时管理添加和删除侦听器。



Bindings.select 方法应该有助于管理这样的事情,但是从JavaFX 8开始,它打印出巨大的堆栈每次遇到空值时都会将输出跟踪到警告,这是经常发生的。因此,我建议您自己进行监听器管理,直到修复为止。 (出于某种原因,JavaFX团队似乎并不认为这是一个大问题,即使在API文档中明确支持在Bindings.select中定义的路径中遇到空值。)



只是为了让它更令人不愉快, TableCell< S,T> getTableRow()方法$ c>返回 TableRow ,而不是更明显的 TableRow< S> 。 (可能有一个我无法看到的原因,但是,好吧......)。所以你的代码还附带了强制转换。



我创建了一个示例:为它基于美国地理而道歉,但我已经写了很多例子。我真的希望我错过了一些东西,并且有更简单的方法可以做到这一点:如果有人有更好的想法,请随时提出建议。



最后一点: EasyBind 库可能提供一种更简单的方法来绑定任意路径上的属性。


first I must apologize because english isn't my mother language, but I'll try to be clear in what I'm asking.

I have a set of rows in a tableview, every row has diferent comboboxs per columns. So, the interaction between combobox must be per row. If in the Combobox A1, I select Item 1, in the Combobox A2 the itemlist will be updated. My problem is that every combobox A2, B2, C2, etc. Is being updated according the choice in A1... same thing with B1,C1 combobox. I need to updated just the A2, according to A1. B2 according to B1, etc.

I set the comboboxes by cellfactory, because I have to save the data from behind in a serializable object.

Hope is clear.

Regards.

解决方案

This is pretty much a pain...

From a TableCell, you can observe the TableRow via it's tableRowProperty().

From the TableRow, you can observe the item in the row, via the table row's itemProperty().

And of course, from the item in the row, you can observe any properties defined in your model class, and update a list of items in the combo box accordingly.

The painful part is that any of these value can, and will at some point change. So the things you need to observe keep changing, and you have to manage adding and removing listeners as this happens.

The Bindings.select method is supposed to help manage things like this, but as of JavaFX 8, it prints huge stack traces to the output as warnings whenever it encounters a null value, which it does frequently. So I recommend doing you own listener management until that is fixed. (For some reason, the JavaFX team doesn't seem to consider this a big deal, even though encountering null values in the path defined in a Bindings.select is explicitly supported in the API docs.)

Just to make it slightly more unpleasant, the getTableRow() method in TableCell<S,T> returns a TableRow, instead of the more obvious TableRow<S>. (There may be a reason for this I can't see, but, well...). So your code is additionally littered with casts.

I created an example that works: apologies for it being based on US geography, but I had much of the example already written. I really hope I'm missing something and that there are easier ways to do this: please feel free to suggest something if anyone has better ideas.

On last note: the EasyBind library may provide a simpler way to bind to the properties along an arbitrary path.

这篇关于根据另一个ComboBox选项更改ComboBox中的ItemList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆