How to change the style of ScrallBar ?

Such a thing does not work:

 scroll.getStyleClass().add(".scroll-pane .thumb {-fx-background-color:derive(black,90%);" + "-fx-background-insets: 0, 0, 0;-fx-background-radius: 0em;}"); 

I tried to find some info on Skin , but there is nothing besides the Oracle docks.

So how to make custom elements in ScrollBar ?

    1 answer 1

    In the return collection getStyleClass() you need to add not the style, but the name of the class described in css . Styles can be written in .setStyle( "-fx-..." ); but for inner classes like .thumb or selectors this will not work. So something like this:

     scroll.getStylesheets().add( MainApplication.class.getClassLoader().getResource("/main.css").toExternalForm() ); scroll.getStyleClass().add( "myClass" ); //scroll.setId( "myId" ); 

    main.css

     .myClass .thumb { -fx-background-color:derive(black,90%); -fx-background-insets: 0, 0, 0; -fx-background-radius: 0em; } /* #myId .thumb { -fx-background-color:derive(black,90%); -fx-background-insets: 0, 0, 0; -fx-background-radius: 0em; } */ 

    An alternative option without a css file (it seems to work, but did not check):

     for ( Node n : scrool.lookupAll( ".trumb" ) ){ n.setStyle("-fx-background-color:derive(black,90%);" + "-fx-background-insets: 0, 0, 0;-fx-background-radius: 0em;" ); }