简体   繁体   English

禁用JavaFX TableColumn

[英]Disable JavaFX TableColumn

Have a TableColumn defined as TableColumn<Target, String> tableColumnLocation; TableColumn定义为TableColumn<Target, String> tableColumnLocation; and is populated like this: 并像这样填充:

tableColumnLocation.setCellValueFactory(new 
PropertyValueFactory<Target, String>("name"));

tableColumnLocation.setCellFactory(ComboBoxTableCell.forTableColumn(locationValues));

where locationValues are set of Strings read from a database. 其中locationValues是从数据库读取的字符串集。 Am trying to disable the tableColumnLocation dropdown in case another checkbox column is unselected. 我试图禁用tableColumnLocation下拉列表,以防未选中另一个复选框列。 So the issue is how to disable ComboBoxTableCell . 因此,问题在于如何禁用ComboBoxTableCell Any recommendations would be highly appreciated. 任何建议将不胜感激。
Have been able to disable other TableColumn as shown below but not sure on how to proceed on this one. 能够禁用其他TableColumn ,如下所示,但不确定如何继续进行此操作。

tableColumnQty.setCellFactory(
                     new Callback<TableColumn<Test, String>, TableCell<Test, String>>() {

                         @Override
                         public TableCell<Test, String> call(TableColumn<Test, String> paramTableColumn) {
                             return new TextFieldTableCell<Test, String>(new DefaultStringConverter()) {
                                 @Override
                                 public void updateItem(String s, boolean b) {
                                     super.updateItem(s, b);
                                     if(!isEmpty()) {
                                         Test item = getTableView().getItems().get(getIndex());
                                         if (item.getTarget().equalsIgnoreCase("0")) {
                                             setDisable(true);
                                             setEditable(false);
                                             this.setStyle("-fx-background-color: lightgrey");
                                         } else {
                                             setDisable(false);
                                             setEditable(true);
                                             //if(s != null && !s.equalsIgnoreCase(""))

                                             setStyle("");
                                         }
                                     }
                                 }
                             };
                         }

                     });

Here is what you need: 这是您需要的:

tableColumnLocation.setCellFactory(
                     new Callback<TableColumn<Target, String>, TableCell<Target, String>>() {

                         @Override
                         public TableCell<Target, String> call(TableColumn<Target, String> paramTableColumn) {
                             return new ComboBoxTableCell<Target, String>(new DefaultStringConverter(), locationValues) {
                                 @Override
                                 public void updateItem(String s, boolean b) {
                                     super.updateItem(s, b);
                                     if(!isEmpty()) {
                                         Target item = getTableView().getItems().get(getIndex());
                                         if (check if checkbox is unselected) {
                                             setDisable(true);
                                             setEditable(false);
                                             this.setStyle("-fx-background-color: lightgrey");
                                         } else {
                                             setDisable(false);
                                             setEditable(true);
                                             setStyle("");
                                         }
                                     }
                                 }
                             };
                         }

                     });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM