I want to make text strikethrough using CSS.
I use tag:
button.setStyle("-fx-strikethrough: true;");
But this code is working, please help.
I want to make text strikethrough using CSS.
I use tag:
button.setStyle("-fx-strikethrough: true;");
But this code is working, please help.
Button
does not support the-fx-strikethrough
CSS property, so setting this has no effect.Here is the official JavaFX 8 CSS reference: JavaFX CSS Reference Guide
The
-fx-strikethrough
is defined for theText
node.Button
only supports the following:cancel
,default
, and all inherited fromLabeled
:And
Labeled
inherits these fromControl
:-fx-skin
,-fx-focus-traversable
.So looking at the supported properties, the following works (of course it's not strikethrough):
You need to use a CSS stylesheet to enable strikethrough on a button. Using a CSS stylesheet is usually preferable to using an inline CSS setStyle command anyway.
The CSS style sheet uses a CSS selector to select the text inside the button and apply a strikethrough style to it. Currently (as of Java 8), setStyle commands cannot use CSS selectors, so you must use a CSS stylesheet to achieve this functionality (or use inline lookups, which would not be advisable) - the style sheet is the best solution anyway.
See @icza's answer to understand why trying to set the
-fx-strikethrough
style directly on the button does not work.Here is a sample application: