JavaFX8:Hide/Remove TableView 中的垂直滚动条
JavaFX8: Hide/Remove vertical scrollbar in TableView
我想隐藏或删除 TableView 中的垂直滚动条。我想用我自己的 PgUp/PgDown 按钮来管理滚动。
按钮可以在下面的代码中正常工作,但 verticalScrollBar 破坏了所需的方面。我怎样才能hide/remove呢?
btnPgDown.setOnAction(e -> {
if (table.getSelectionModel().getSelectedIndex() == -1) {
table.getSelectionModel().select(0);
}
Event.fireEvent(table, EventUtil.PG_DN_PR_EVENT);
table.requestFocus();
});
注意:EventUtil.PG_DN_PR_EVENT 模拟 PgDown 键事件。
根据我自己的经验,TableView
是否显示 ScrollBar
取决于 ScrollBar
上的按钮和箭头。
在我的项目中,我使用此 CSS 代码来隐藏两个滚动条
.table-view *.increment-button,
.table-view *.decrement-button,
.table-view *.increment-arrow,
.table-view *.decrement-arrow
{
-fx-padding: 0;
-fx-shape: "";
}
但这有副作用,因为显然 TableMenuButton
使用相同的填充 TableMenuButton
以填充 0 消失,我唯一看到的是“+”号的一半通常显示在按钮上。所以这是 a 方式但不一定是 the 方式。
我认为隐藏 TableView 滚动条的最佳方法是使用 CSS 代码。
这是垂直滚动条的代码。
.table-view *.scroll-bar:vertical *.increment-button,
.table-view *.scroll-bar:vertical *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.table-view *.scroll-bar:vertical *.increment-arrow,
.table-view *.scroll-bar:vertical *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
如果您还想隐藏水平滚动条,您必须添加相同的代码,但将 *.scroll-bar:vertical
更改为 *.scroll-bar:horizontal
。
如果您想通过代码滚动 table,我建议使用 TableView class.
中包含的方法 scrollTo
我想隐藏或删除 TableView 中的垂直滚动条。我想用我自己的 PgUp/PgDown 按钮来管理滚动。
按钮可以在下面的代码中正常工作,但 verticalScrollBar 破坏了所需的方面。我怎样才能hide/remove呢?
btnPgDown.setOnAction(e -> {
if (table.getSelectionModel().getSelectedIndex() == -1) {
table.getSelectionModel().select(0);
}
Event.fireEvent(table, EventUtil.PG_DN_PR_EVENT);
table.requestFocus();
});
注意:EventUtil.PG_DN_PR_EVENT 模拟 PgDown 键事件。
根据我自己的经验,TableView
是否显示 ScrollBar
取决于 ScrollBar
上的按钮和箭头。
在我的项目中,我使用此 CSS 代码来隐藏两个滚动条
.table-view *.increment-button,
.table-view *.decrement-button,
.table-view *.increment-arrow,
.table-view *.decrement-arrow
{
-fx-padding: 0;
-fx-shape: "";
}
但这有副作用,因为显然 TableMenuButton
使用相同的填充 TableMenuButton
以填充 0 消失,我唯一看到的是“+”号的一半通常显示在按钮上。所以这是 a 方式但不一定是 the 方式。
我认为隐藏 TableView 滚动条的最佳方法是使用 CSS 代码。
这是垂直滚动条的代码。
.table-view *.scroll-bar:vertical *.increment-button,
.table-view *.scroll-bar:vertical *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.table-view *.scroll-bar:vertical *.increment-arrow,
.table-view *.scroll-bar:vertical *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
如果您还想隐藏水平滚动条,您必须添加相同的代码,但将 *.scroll-bar:vertical
更改为 *.scroll-bar:horizontal
。
如果您想通过代码滚动 table,我建议使用 TableView class.
中包含的方法 scrollTo