简体   繁体   English

通过fxml链接样式表时,JavaFX Tooltop样式样式类将不适用

[英]JavaFX tooltop styling class won't apply when the stylesheet is linked via fxml

I have a function in my control class as below, and I have linked the css file with fxml. 我的控件类中有一个函数,如下所示,并且我已将css文件与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 . 我在这里找到了JavaFX Tooltip定制的确切问题。 But it doesn't provide any solution to the problem, and is asked about 3 years ago. 但这并不能提供解决问题的方法,大约在3年前就被要求使用。 Here I have linked the the css file in fxml. 在这里,我已经在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">

Please write the full path after src package. 请在src软件包后写完整路径。 For example; 例如;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM