问题描述
我正在JavaFx中创建一个应用程序。现在我有两个相邻的tableviews:
I'm creating an application in JavaFx. Right now I have two tableviews next to each other:
------------------------------------------------------------------------------
| TableView 1 | TableView 2 |
| | |
| | Entry 1 |
| | Entry 2 |
| | Entry 3 |
| | Entry ... |
| | Entry N |
------------------------------------------------------------------------------
我想将TableView 2中的项目复制到TableView 1,但同时,需要禁用从TableView 2复制的条目(使用setDisable禁用行或相似的东西)。我知道如何将项目从一个tableview复制到另一个tableview。问题是,当一个或多个条目被复制到TableView 1时,我不知道如何禁用多行。
我尝试使用RowFactory,如下所示:
I would like to copy items from TableView 2 to TableView 1, but at the same time, the entries that have been copied from TableView 2 need to be disabled (disable the row with setDisable or something similar). I do know how to copy the items from one tableview to another. The problem is that I do not know how to disable multiple rows when one or multiple entries have been copied to TableView 1.I tried this with a RowFactory, like this:
productsInTransaction.setRowFactory(tv -> {
TableRow<Product> row = new TableRow<>();
row.disableProperty().bind(???);
return row;
});
非常感谢任何帮助!
推荐答案
我不太确定你想要的逻辑,但如果您的行工厂附加到表1,并且当表2中存在该项时您正在禁用该行,执行:
I'm not quite sure of the logic you're wanting, but if your row factory is attached to table 1, and you are disabling the row when the item is present in table 2, do:
row.disableProperty().bind(Bindings.createBooleanBinding(() ->
table2.getItems().contains(row.getItem()), table2.getItems(), row.itemProperty()));
这篇关于JavaFX:基于其他TableView在TableView中禁用多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!