Hello I’m back with the small css skinning for the Tooltip.
Firstly the idea of this blogging came from this forum post. One guy was posting about how to make the tooltip plain as of swing which is concern about the css skinning.
First let’s get start with the normal tooltip example.
public class TooltipTest extends Application {
public static void main(String[] args) {
Application.launch(TooltipTest.class, args);
}
@Override
public void start(Stage primaryStage) throws Exception {
StackPane stackPane = new StackPane();
Button butt = new Button("Test hello");
Tooltip tp= new Tooltip("Hello this is only the test");
tp.getStyleClass().add("ttip");
butt.setTooltip(tp);
stackPane.getChildren().add(butt);
Scene sc = new Scene(stackPane,500,500);
sc.getStylesheets().add(getClass().getResource("gui.css").toExternalForm());
primaryStage.setScene(sc);
primaryStage.show();
}
}
Here I’ve added my custom css file ‘gui.css’ for styling this application.
gui.css
.ttip{
-fx-background-radius: 0 0 0 0;
}
.page-corner {
-fx-shape: " ";
}
Let’s Play with the CSS.
.ttip{
-fx-background-radius: 7 7 7 7;
}
.ttip{
-fx-background-radius: 0 0 0 0;
-fx-background-color: linear-gradient(greenyellow , limegreen );
}
.ttip{
-fx-background-radius: 0 0 0 0;
-fx-background-color: linear-gradient(orange, orangered );
}
.ttip{
-fx-background-radius: 0 0 0 0;
-fx-background-color: linear-gradient(cyan , deepskyblue );
}
I hope you guys enjoy with this small CSS stuffs. This much for today.
Thanks.






Pingback: JavaFX links of the week, March 12 // JavaFX News, Demos and Insight // FX Experience
Trackback: inspiration
#1 by Nicolas on May 14, 2012 - 12:05 am
Quote
Hi Narayan,
Nice blog post, thank you! I have tried your tooltip skinning with JavaFX 2.1 and I haven’t succeeded in removing the page corner.
Nicolas
#2 by Narayan G. Maharjan on May 14, 2012 - 12:55 am
Quote
Hi Nicolas,
are you sure you have used the background-radius property of the css ?
Thanks
#3 by Nicolas on May 14, 2012 - 3:05 am
Quote
Yes, I have tried with this CSS:
.ttip {
-fx-background-radius: 5 5 5 5;
}
.page-corner {
-fx-shape: “”;
}
The page corner is still displayed but the radius is applied to the tooltip.
#4 by Narayan G. Maharjan on May 14, 2012 - 5:45 pm
Quote
Hi Nicolas,
I think the inverted comma you have given in -fx-shape property is not correct. Please use the correct inverted comma. All of your code is just correct I’ve tested and it works on mine .
Thanks
Narayan.
#5 by Nicolas on May 15, 2012 - 12:59 pm
Quote
Hi Narayan,
Hum, it’s weird, I have done a copy-paste from your source code…
I have tried with this SVG path “M 0 0 z” for the page corner shape and then the page corner hasn’t been displayed.
Thanks.
Nicolas
#6 by Enrique on May 20, 2012 - 3:06 am
Quote
Good article Narayan,
I have been trying to style the tooltip recently and was very interested in your article. One thing that I was not able to acomplish, is to change the font color. I hoped you had tried this in your tests, but I see you havent.
Have you been able to acomplish this?
Thanks,
Enrique
#7 by Narayan G. Maharjan on May 20, 2012 - 9:51 am
Quote
Hi Enrique,
To color your text you need to add this attribute. Suppose you are going to color the text with red color then the css must be like this.
.ttip{
-fx-text-fill:red;
}
Thanks
Narayan
#8 by Enrique on May 20, 2012 - 12:06 pm
Quote
Yes, that would be the obvious way. But unfortunately it doesn’t work in Javafx 2.1. Many things don’t work as expected in the CSS styling, but otherwise I’m very happy with Javafx.
#9 by Narayan G. Maharjan on May 27, 2012 - 12:23 pm
Quote
Hello Enrique,
I ‘ve also looked on the this things in 2.1 and saw same problem. And found that we need to use like this to work correctly:
.page-corner {
-fx-shape: " ";
}
In above i’ve used space inside value of -fx-shape .
Thanks
Narayan
#10 by baikelin on August 3, 2012 - 12:12 pm
Quote
Hi
is there a way to define how long the popup windows pops up
cheers
#11 by Narayan G. Maharjan on August 3, 2012 - 1:33 pm
Quote
Currently there is nothing like that . But I would recommend you to add some event handler in mouseOut and mouseIn of the Control where you are using that Tooltip. And control the disable and enable of the Tooltip by using hide() or show() function . Or even more you can control the timing of the hiding the Tooltip on event handler of onShowingProperty
#12 by Leonardo on April 2, 2013 - 9:17 pm
Quote
Is there any limitation according to JavaFX version? I’m using JavaFx 2.2.7 and the CSS code don’t work:
.ttip{
-fx-background-radius: 0 0 0 0;
-fx-background-color: linear-gradient(cyan , deepskyblue );
-fx-text-fill: white;
}
.page-corner {
-fx-shape: ” “;
}
#13 by Narayan G. Maharjan on April 7, 2013 - 2:09 pm
Quote
@leonardo,
all css are same
#14 by Carlos de Luna Saenz on April 26, 2013 - 9:13 pm
Quote
.ttoltip as the default css style is not working…. at least here using Java 8 sith build 86… and it didn’t worked on 2.1 or 2.2 we need to use the “base” css class cause we have several (houndreds may be) tooltips on our App and we don’t want to take the risk to loose any of them on applying the style.
#15 by Narayan G. Maharjan on April 29, 2013 - 4:09 pm
Quote
Hi carlos,
.ttoltip is not the default css style class use .tooltip instead. Did you see that I used “.ttip” because I have defined
getStyleClass().add("ttip");. If you don’t want the user-defined class then use base class “.tooltip“.Thanks
Narayan
#16 by Carlos de Luna Saenz on April 29, 2013 - 7:17 pm
Quote
I meant .tooltip … it didn’t work .ttoltip was a “finger mistake”… my CSS says:
.tooltip{
-fx-background-color: linear-gradient(blue,lightskyblue);
-fx-background-radius: 5;
-fx-wrap-text: true;
}
and using JavaFX 2.2 there’s no change on the “yellow” tooltip style, using Build 86 of Java 8 the tooltip is black, cause that’s the default since build 84.. something wrong with that CSS definition?
#17 by Narayan G. Maharjan on April 29, 2013 - 8:40 pm
Quote
Hi Carlos,
Your css works perfectly. I have tested. The output of your tooltip css is like this: http://s10.postimg.org/kjexdogw9/Untitled.png
Button b = new Button("sdfasd"); Tooltip t = new Tooltip(); t.setText("Check on this "); b.setTooltip(t); Scene scene = new Scene(b, 300, 250); scene.getStylesheets().add("file:///c:/guis.css");I am using jdk1.7.0_13 with javafx 2.2.5.
Thanks