import javafx.application.Application; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ScrollPane; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.control.TitledPane; import javafx.scene.layout.StackPane; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class Test extends Application { private Scene scene = null; public static void main(String[] args) { Application.launch(Test.class, (String[]) null); } public void start(Stage stage) { scene = new Scene(new Group()); scene.getStylesheets().add(Test.class.getResource("test.css").toExternalForm()); stage.setTitle("TEST"); stage.setWidth(500); stage.setHeight(500); stage.setScene(scene); stage.show(); final TitledPane titledPane = new TitledPane("Title", null); titledPane.setContent(new Rectangle(50, 200)); titledPane.setMaxWidth(Long.MAX_VALUE); titledPane.setMinWidth(0); final StackPane stackPane1 = new StackPane(); stackPane1.getChildren().add(titledPane); final ScrollPane scrollPane = new ScrollPane(); scrollPane.setFitToWidth(true); scrollPane.setContent(stackPane1); scrollPane.viewportBoundsProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable observable) { final Node content = scrollPane.getContent(); final double viewPortHeight = scrollPane.getViewportBounds().getHeight(); final double contentHeight = content.prefHeight(0); final boolean isScrollBarVisible = (viewPortHeight < contentHeight); if (isScrollBarVisible) { // Scroll bar is visible content.getStyleClass().remove("scrollBarNotVisible"); // Check css rule has not been already added if (!content.getStyleClass().contains("scrollBarVisible")) { content.getStyleClass().add("scrollBarVisible"); } } else { // Scroll bar is not visible content.getStyleClass().remove("scrollBarVisible"); // Check css rule has not been already added if (!content.getStyleClass().contains("scrollBarNotVisible")) { content.getStyleClass().add("scrollBarNotVisible"); } } } }); final StackPane stackPane2 = new StackPane(); stackPane2.getChildren().add(scrollPane); final TabPane tabPane = new TabPane(); Tab tab = new Tab(); tab.setText("Tab"); tab.setContent(stackPane2); tabPane.getTabs().addAll(tab); ((Group) scene.getRoot()).getChildren().addAll(tabPane); } }