I would like to hide or remove vertical scrollbar in my TableView. I would like to menage scroll with my own PgUp/PgDown buttons.
Buttons work fine with below code, but the verticalScrollBar ruin the desired aspect. How can I hide/remove it?
btnPgDown.setOnAction(e -> {
if (table.getSelectionModel().getSelectedIndex() == -1) {
table.getSelectionModel().select(0);
}
Event.fireEvent(table, EventUtil.PG_DN_PR_EVENT);
table.requestFocus();
});
Note: the EventUtil.PG_DN_PR_EVENT emulate the PgDown key event.
I think the best way to hide the scroll bars of a TableView is with CSS code.
This is the code for the vertical scroll bar.
.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;
}
If you want to hide also the horizontal scroll bar, you have to add the same code but changing *.scroll-bar:vertical
for *.scroll-bar:horizontal
.
And if you want to scroll your table by code, I recommend to use the method scrollTo that it's included in the TableView class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With