0

I would like to set a standard for all tooltips to be a specific width and have word wrap on. I would like to override the tooltip style. However I am unsure how to set those properties.

I can do it in code like this:

Tooltip taskname = new Tooltip();
taskname.setWrapText(true);
taskname.setPrefWidth(250);

enter image description here

However, I would prefer to set it once in the CSS - I tried like this but it didn't wrap:

.tooltip {
    -fx-background: rgba(255,255,205);
    -fx-text-fill: black;
    -fx-background-color: rgba(255,255,205,0.95);
    -fx-background-radius: 6px;
    -fx-background-insets: 0;
    -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */
    -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );
    -fx-font-size: 0.90em;
    -fx-wrap-text: true;
    -fx-pref-width: 250;
    -fx-max-width: 250;

}

But I am not sure how to go about setting that. These settings don't seem to work for me.

enter image description here

Any help would be appreciated.

Thank you

purring pigeon
  • 4,141
  • 5
  • 35
  • 68
  • [`Tooltip::setPrefWidth`](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/PopupControl.html#setPrefWidth-double-) is a property of PopupControl, which is a [PopupWindow](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#popupwindow). According to the [JavaFX CSS reference guide](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#popupwindow), "PopupWindow does not have any properties that can be styled by CSS". So you can't define `-fx-pref-width` for tooltips using CSS. – jewelsea Aug 22 '16 at 22:27
  • Thanks for the response. Just weird that it has -fx-wrap-text but you can't say how wide it should be. – purring pigeon Aug 23 '16 at 04:39
  • I guess I could extend tooltip and just set the max width that way in the constructor. – purring pigeon Aug 25 '16 at 15:58

0 Answers0