2

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.

Mouz
  • 273
  • 2
  • 13

1 Answers1

4

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.

OttPrime
  • 1,878
  • 1
  • 15
  • 24
  • Thanks for the answer, I went into the css (in the jdk) that defines the default properties of the tooltip (caspian.css) and I can see that they set those properties (even saw an example [here](http://blog.ngopal.com.np/2012/03/07/css-tooltip-skinning/)). Anyways, it doesn't really explain why this is working in the Java Scene Builder and with the getStylesheets().add(...) instruction. – Mouz Jun 26 '13 at 15:04
  • Interesting. I see that now as well. I'm curious as to why those are left out of the CSS resource link. Have you looked at [this](http://stackoverflow.com/questions/14696884/setting-stylesheets-declaratively-in-fxml/14697419#14697419) answer to a similar question? Do you have the style sheet linked directly using the import? – OttPrime Jun 27 '13 at 14:58
  • Seems that this import is only useful for the Scene Builder. I tried it out anyways but it still does not work. I posted the issue on the JIRA board, I'll see what comes from it. – Mouz Jul 03 '13 at 14:15