我想根据树中的级别控制 TreeTableView 某些行的样式。setRowFactory如果此行是表根的第一级子级的一部分,我使用并应用了样式。样式工作正常,但我也想禁用单击这些行的复选框。我能够,setDisable(true)但这也禁用了 TreeItem 的扩展,并且SetEditable(false)似乎没有任何效果。
编辑:我的理解是必须将表设置为可编辑,然后列在默认情况下是可编辑的。但是如果我设置了,TreeTableRow.setEditable(true);或者TreeTableRow.setEditable(false);我从来没有看到任何效果。setEditable 的描述似乎正是我想要的,但我无法那样使用它。
void javafx.scene.control.Cell.setEditable(boolean arg0)
setEditable public final void setEditable(boolean value)
允许某些单元格无法编辑。这在以下情况下很有用,例如,列表具有“标题行”-标题行 > 可编辑没有意义,因此它们应该将可编辑设置为 false。参数:value - 表示单元格是否可编辑的布尔值。如果 >true,单元格可编辑,如果为 false,单元格不可编辑。
主要的:
public class TreeTableViewRowStyle extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
// create the treeTableView and colums
TreeTableView<Person> ttv = new TreeTableView<Person>();
TreeTableColumn<Person, String> colName = new TreeTableColumn<>("Name");
TreeTableColumn<Person, Boolean> colSelected = new TreeTableColumn<>("Selected");
colName.setPrefWidth(100);
ttv.getColumns().add(colName);
ttv.getColumns().add(colSelected);
ttv.setShowRoot(false);
ttv.setEditable(true);
// set the columns
colName.setCellValueFactory(new TreeItemPropertyValueFactory<>("name"));
colSelected.setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(colSelected));
呼啦一阵风
largeQ
相关分类