JavaFX tooltop样式类赢得';当样式表通过fxml链接时,不适用

JavaFX tooltop样式类赢得';当样式表通过fxml链接时,不适用,java,css,javafx,tooltip,fxml,Java,Css,Javafx,Tooltip,Fxml,我的控件类中有一个函数,如下所示,并且我已经将css文件与fxml链接。但是如果我不手动加载样式表,则不会应用相关的样式类 private void ValidateRequired(TextField field){ Tooltip errorm = new Tooltip("This is required"); errorm.getStyleClass().removeAll(); Scene scene = field.getScene(); scene

我的控件类中有一个函数,如下所示,并且我已经将css文件与fxml链接。但是如果我不手动加载样式表,则不会应用相关的样式类

 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);
}
我在这里找到了确切的问题。但它并没有为这个问题提供任何解决方案,而且是在大约3年前提出的。在这里,我链接了fxml中的css文件

 <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">

请在src包后填写完整路径。比如,

<GridPane prefHeight="1031.0" prefWidth="821.0" stylesheets="@/com/test/css/Sale.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="BikeShop.control.SaleControl">


工具提示
s是特殊的:它们不是
节点
s,而是
弹出控件
s。在FXML文件中指定样式表时,该样式表将添加到FXML文件根节点的样式表列表中(哪个节点将是
场景的scenegraph的一部分,很可能是根节点)。问题:
工具提示
不是此节点的子节点,因此不应用它。当您执行
scene.getStylesheets().add()
时,您会将文件附加到
场景
,因此它会应用到
工具提示
。我担心从FXML无法做到这一点,
场景
未知。我希望有人能证明我错了:)谢谢您的解释,我也找到了类似的解释,如果是这种情况,我可能必须在每次启动工具提示时加载样式表。我希望有一些解决办法。