我创建了一个包含3列的表格。在中间一栏中,我有3个复选框。当我的窗口初始化时,如果来自数据库的信息合适,则选中复选框。有用。用户可以取消选中数据库中哪些更改信息的复选框。我的问题是,当我确认一次选中复选框时返回true,一次返回false,但是复选框处于相同状态(是否选中)。
public CheckBox podglad2, edycja2, dodawanie2, usuwanie2, importowanie2, eksportowanie2, nadawanie2;
private static void setAccessLabelStyle2(CheckBox label, AccessLevel level, Integer value) {
if (check(level, value)) {
label.setSelected(true);
} else {
label.setSelected(false);
}
}
private static boolean check(AccessLevel accessLevel, Integer value) {
return (accessLevel.getBit() & value) > 0;
}
public TableCell getFunctionCell2(TableCell cell, Integer accessLevel) {
HBox graphics = new HBox();
graphics.setAlignment(Pos.CENTER_LEFT);
graphics.setSpacing(7.0);
podglad2 = new CheckBox("P");
setAccessLabelStyle2(podglad2, AccessLevel.VIEW, accessLevel);
dodawanie2 = new CheckBox("D");
setAccessLabelStyle2(dodawanie2, AccessLevel.CREATE, accessLevel);
edycja2 = new CheckBox("E");
setAccessLabelStyle2(edycja2, AccessLevel.UPDATE, accessLevel);
}
accessLevelCol.setCellFactory(param -> {
return new TableCell<FunctionTableModel, Integer>() {
@Override
protected void updateItem(Integer item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
setStyle("");
} else {
getFunctionCell2(this, item);
podglad2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.VIEW, row.getAccessLevel())) {
if (podglad2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.VIEW.getBit());
}
} else {
if (podglad2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.VIEW.getBit());
}
}
});
dodawanie2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.CREATE, row.getAccessLevel())) {
if (dodawanie2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.CREATE.getBit());
}
} else {
if (dodawanie2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.CREATE.getBit());
}
}
});
edycja2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.UPDATE, row.getAccessLevel())) {
if (edycja2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.UPDATE.getBit());
}
} else {
if (edycja2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.UPDATE.getBit());
}
}
});
}
我该如何解决?