我想将 datagridview 列向右对齐,但我不想更改我设置的 datagridview 列的宽度。我有八列,第二列的属性“可调整大小”设置为 true ,其余的为“可调整大小=” false。当我展开 datagridview 或窗口时,除第二列之外的列的宽度不应展开。怎么做。属性填充并不像我想要的那样工作。我展开所有列并赋予它们自己的宽度。但我想保留列的宽度,因为除了第二列之外,它们已经设置好了。
主页
/
user-23350128
Marian34's questions
Marian34
Asked:
2024-02-23 06:40:12 +0800 CST
我想让我的切换按钮列在我的 TableView 中正常工作。当我按下切换按钮时,什么也没有发生。如何修复这个问题?我没有更改“Medicaments.java”模型中的任何内容。看起来就像您在下面看到的那样:
@FXML
private TableColumn<Medicaments, Void> editRow;
我的型号:
public Medicaments(int idNumber, String LOTNumber, String medName, String dateExpiry, int quantity, String unit,String timeLeft) {
this.idNumber = idNumber;
this.LOTNumber = LOTNumber;
this.medName = medName;
this.dateExpiry = dateExpiry;
this.quantity = quantity;
this.unit = unit;
this.timeLeft = timeLeft;
}
切换按钮列:
private void AddEditButton() {
TableColumn<Medicaments, Void> colBtn = new TableColumn("");
Callback<TableColumn<Medicaments, Void>, TableCell<Medicaments, Void>> cellFactory = new
Callback<TableColumn<Medicaments, Void>, TableCell<Medicaments, Void>>() {
@Override
public TableCell<Medicaments, Void> call(final TableColumn<Medicaments, Void> param)
{
final TableCell<Medicaments, Void> cell = new TableCell<Medicaments, Void>() {
private final ToggleButton toggleButton = new ToggleButton("Edit");
{
/**/
toggleButton.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
event.consume();
toggleButton.selectedProperty().addListener((observable,oldValue,
newValue) -> {
if(newValue){
toggleButton.setText("Save");
} else {
toggleButton.setText("Edit");
}
});
});
/*btn.addEventFilter(MouseEvent.MOUSE_PRESSED, event ->{
event.consume();
Medicaments data = getTableView().getItems().get(getIndex());
System.out.println("selectedData: " + data);
});*/
}
@Override
public void updateItem(Void item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
setGraphic(toggleButton);
}
}
};
return cell;
}
};
editRow.setCellFactory(cellFactory);
}