Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize javafx scrollbar thumb thickness by css?

I tried to set thickness by -fx-pref-height: 10px; when orientation is horizontal, and by -fx-pref-width: 10px; when scrollbar orientation is vertical. But is doesn't work.

.scroll-bar:horizontal .thumb {
    -fx-background-color: derive(black, 90%);
    -fx-background-insets: 2, 0, 0;
    -fx-background-radius: 0em;
    -fx-pref-height: 10px;
}

.scroll-bar:vertical .thumb {
    -fx-background-color: derive(black, 90%);
    -fx-background-insets: 2, 0, 0;
    -fx-background-radius: 0em;
    -fx-pref-width: 10px;
}

How to achieve this by customizing css?

like image 671
Vanguard Avatar asked May 14 '17 19:05

Vanguard


People also ask

How do I change the scrollbar width?

Double-click/tap on ScrollHeight. The Edit String window will open with the default value of -255. That is the standard size of the scrollbars you see on Windows. To change the Scrollbars height to your liking, enter a value between -120 (smaller) to -1500 (larger) for the size you want, and click/tap on OK.

Can you style scrollbars?

The scrollbar width First, we need to define the size of the scrollbar. This can be the width for vertical scrollbars, and the height for horizontal ones. With that set, we can style the scrollbar itself.

Can we change the height of the scrollbar thumb?

the height of the thumb is based in the size of content, you can change the width inside the ::-webkit-scrollbar but the height will always be based on the content.


1 Answers

you can set the padding of the scrollbars to shrink the thumbs' thickness.

.scroll-bar:vertical {
    -fx-pref-width: 16.5;
    -fx-padding: 3;
}

.scroll-bar:horizontal {
    -fx-pref-height: 16.5;
    -fx-padding: 3;
}

.scroll-bar, .scroll-bar:pressed, .scroll-bar:focused {
    -fx-font-size: 15;
}
like image 54
Pakbert Avatar answered Sep 18 '22 18:09

Pakbert