Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

css - JavaFX Tooltip customisation

I encountered the following issue using JavaFX.

Redefinition of tooltip style using stylesheet works in Java Scene Builder.

Redefinition of tooltip style at execution in eclipse with the same stylesheet included in FXML file generated from scene builder with

<stylesheets>
    <URL value="@../style/myCSS.css" />
</stylesheets>

does not work (any other property redefinition works).

Redefinition of tooltip style at execution in eclipse with same stylesheet using code instruction :

scene.getStylesheets().add(this.getClass().getResource("/style/myCSS.css").toExternalForm());

works properly.

Stylesheet used (myCSS.css):

.tooltip {
    -fx-background-radius: 2 2 2 2;
    -fx-background-color: linear-gradient(#FFFFFF, #DEDEDE);
}

.page-corner {
    -fx-shape: " ";
}

AnchorPane {
    -fx-background-color: firebrick;
}

FXML file used:

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="91.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml">
  <children>
    <Button layoutX="72.0" layoutY="35.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button">
      <tooltip>
        <Tooltip text="Tootip Text" />
      </tooltip>
    </Button>
  </children>
  <stylesheets>
    <URL value="@../style/myCSS.css" />
  </stylesheets>
</AnchorPane>

Edit: In other words I want to be abe to declare my stylesheet in the FXML file. Doing so seems to work for any property redefinition (AnchorPane background color in this case) except tooltips.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The CSS properties you are trying to set for the Tooltip are only relavent to JavaFX classes that extend the Region class. The Tooltip is a child of the PopupControl class and, as such, has a more limited CSS property library. Here's a link to a list of available CSS properties for Tooltip. That site is your best reference for JavaFX CSS properties.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...