我在使用javafx程序时遇到问题,我创建了一个带有某些列的tableview,其中一个可以填充很多文本,因此我想在单元格中使用一个滚动条,该滚动条长于显示的宽度。目前,创建特定列的代码是
@FXML
private TableColumn<ARule,String> antCol;
customTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
customTable.setEditable(true);
antCol.prefWidthProperty().bind(customTable.widthProperty().multiply(0.43));
antCol.setCellValueFactory(new PropertyValueFactory<ARule, String>("antecedente"));
其中维是总表的一部分,但是当文本大于单元格的维时,我无法获得水平滚动。
谢谢你的帮助。
我不知道以下代码片段是否可以帮助您:
antCol.setCellFactory(col -> {
TableCell<ARule, String> cell = new TableCell<ARule, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setText(null);
TextArea textArea = new TextArea();
textArea.setPrefColumnCount(4);
textArea.setPrefRowCount(1);
textArea.setText(item);
setGraphic(textArea);
}
}
};
return cell;
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句