JavaFX水平滚动条进入TableView的单元格
JavaFX horizontal scrollbar into cell of TableView
我的 javafx 程序有问题,我创建了一个包含某些列的 table 视图,其中一列可以填充大量文本,所以我想在单元格中有一个滚动条长于显示的宽度。
目前创建特定列的代码是
@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"));
尺寸是总尺寸的一部分 table,但当文本大于单元格尺寸时,我无法获得水平滚动。
感谢您的帮助。
我不知道下面的代码片段是否有帮助:
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;
});
我的 javafx 程序有问题,我创建了一个包含某些列的 table 视图,其中一列可以填充大量文本,所以我想在单元格中有一个滚动条长于显示的宽度。 目前创建特定列的代码是
@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"));
尺寸是总尺寸的一部分 table,但当文本大于单元格尺寸时,我无法获得水平滚动。
感谢您的帮助。
我不知道下面的代码片段是否有帮助:
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;
});