I have a function in my control class as below, and I have linked the css file with fxml. But the relevant style class doesn't get applied, If I don't load the stylesheet manually.
private void ValidateRequired(TextField field){
Tooltip errorm = new Tooltip("This is required");
errorm.getStyleClass().removeAll();
Scene scene = field.getScene();
scene.getStylesheets().add(this.getClass().getResource("../css/sale.css").toExternalForm());
//If the above line of code is commented out style will not be applied.
errorm.getStyleClass().add("error");
Point2D p = field.localToScene(0.0, 0.0);
errorm.show((Stage)field.getScene().getWindow(),p.getX()
+ field.getScene().getX() + field.getScene().getWindow().getX(), p.getY()
+ field.getScene().getY() + field.getScene().getWindow().getY()+field.getHeight()+2);
}
I have found the exact problem here JavaFX Tooltip customisation. But it doesn't provide any solution to the problem, and is asked about 3 years ago. Here I have linked the the css file in fxml.
<GridPane prefHeight="1031.0" prefWidth="821.0" stylesheets="@../css/Sale.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="BikeShop.control.SaleControl">