简体   繁体   中英

Disable JavaFX TableColumn

Have a TableColumn defined as 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. Am trying to disable the tableColumnLocation dropdown in case another checkbox column is unselected. So the issue is how to disable 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.

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("");
                                         }
                                     }
                                 }
                             };
                         }

                     });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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