Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX8: Hide/Remove vertical scrollbar in TableView

Tags:

javafx-8

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.

like image 707
mauretto Avatar asked May 11 '18 14:05

mauretto


1 Answers

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.

like image 115
Pablo Insua Avatar answered Oct 22 '22 02:10

Pablo Insua