如何在VBox(JavaFX)中删除表上的滚动条?
我在VBox中有一个TableView,在TableView中有一个非常令人沮丧的滚动条,我无法摆脱它。如有任何帮助,请删除此项,我们将不胜感激 基本上,我在Vbox中有TableView,因为还有一个标签,我想放在TableView上面。任何能实现这一点的替代建议都是很好的 代码:如何在VBox(JavaFX)中删除表上的滚动条?,javafx,tableview,scrollbar,vbox,Javafx,Tableview,Scrollbar,Vbox,我在VBox中有一个TableView,在TableView中有一个非常令人沮丧的滚动条,我无法摆脱它。如有任何帮助,请删除此项,我们将不胜感激 基本上,我在Vbox中有TableView,因为还有一个标签,我想放在TableView上面。任何能实现这一点的替代建议都是很好的 代码: private void setFlagTab(选项卡FlagTab,字符串名称,ArrayList flagList){ TableView table=新TableView(); ObservableList
private void setFlagTab(选项卡FlagTab,字符串名称,ArrayList flagList){
TableView table=新TableView();
ObservableList data=FXCollections.observableArrayList(flagList);
标签=新标签(“标识为:“+名称的标志”);
label.setFont(新字体(“Arial”,20));
TableColumn startCol=新的TableColumn(“开始时间”);
startCol.setCellValueFactory(
新物业价值工厂(“startTime”);
startCol.setSortable(错误);
startCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1));
TableColumn endCol=新的TableColumn(“结束时间”);
endCol.setCellValueFactory(
新财产价值工厂(“endTime”);
endCol.setSortable(假);
endCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1));
TableColumn phaseCol=新的TableColumn(“阶段”);
phaseCol.setCellValueFactory(
新物业价值工厂(“阶段”);
phaseCol.setSortable(假);
phaseCol.prefWidthProperty().bind(table.widthProperty().multiply(0.2));
TableColumn messageCol=新的TableColumn(“消息”);
messageCol.setCellValueFactory(
新属性值工厂(“消息”);
messageCol.setSortable(false);
messageCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4));
TableColumn targetCol=新的TableColumn(“目标”);
targetCol.setCellValueFactory(
新物业价值工厂(“目标”);
targetCol.setortable(假);
targetCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1));
TableColumn Actual=新的TableColumn(“实际”);
实际值设置单元值工厂(
新物业价值工厂(“实际”);
实际可编程逻辑设置(假);
actualCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1));
表2.设置项目(数据);
table.getColumns().addAll(startCol、endCol、phaseCol、messageCol、targetCol、actualCol);
VBox VBox=新的VBox();
vbox.setspace(5);
设置填充(新的插入(10,0,0,10));
vbox.getChildren().addAll(标签、表格);
FlagTab.setText(“标志”);
FlagTab.setContent(vbox);
}
谢谢 考虑以下示例:
TableView table = new TableView();
TableColumn nameCol = new TableColumn("Name");
nameCol.setCellValueFactory(new PropertyValueFactory("name"));
nameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4));
TableColumn surnameCol = new TableColumn("Surname");
surnameCol.setCellValueFactory(new PropertyValueFactory("surname"));
surnameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4));
TableColumn ageCol = new TableColumn("Age");
ageCol.setCellValueFactory(new PropertyValueFactory("age"));
ageCol.prefWidthProperty().bind(table.widthProperty().multiply(0.2));
table.getColumns().addAll(nameCol, surnameCol, ageCol);
StackPane root = new StackPane();
root.getChildren().add(table);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
// Uncomment this line to see the scrollbar
// table.getItems().add(new Person("John", "Doe", 26));
如果按原样运行,它会工作得很好,但看起来很奇怪,一旦向表中添加了一些数据,就会出现水平滚动条。我知道有两种变通办法
multiply(0.4)
替换为multiply(0.39)
table.setColumnResizePolicy(TableView.constrated_RESIZE_策略)代码>
嗨,谢谢你的回答。您的第一个解决方案就是我一直在做的,它并没有完美地显示出来,但这是我找到的最好的解决方案。
TableView table = new TableView();
TableColumn nameCol = new TableColumn("Name");
nameCol.setCellValueFactory(new PropertyValueFactory("name"));
nameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4));
TableColumn surnameCol = new TableColumn("Surname");
surnameCol.setCellValueFactory(new PropertyValueFactory("surname"));
surnameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4));
TableColumn ageCol = new TableColumn("Age");
ageCol.setCellValueFactory(new PropertyValueFactory("age"));
ageCol.prefWidthProperty().bind(table.widthProperty().multiply(0.2));
table.getColumns().addAll(nameCol, surnameCol, ageCol);
StackPane root = new StackPane();
root.getChildren().add(table);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
// Uncomment this line to see the scrollbar
// table.getItems().add(new Person("John", "Doe", 26));