java - not working ccs style javafx -fx-strikethrough -
i want create text strikethrough using css.
i utilize tag:
button.setstyle("-fx-strikethrough: true;");
but code working, please help.
you need utilize css stylesheet enable strikethrough on button. using css stylesheet preferable using inline css setstyle command anyway.
/** file: strikethrough.css (place in same directory strikeout) */ .button .text { -fx-strikethrough: true; }
the css style sheet uses css selector select text within button , apply strikethrough style it. (as of java 8), setstyle commands cannot utilize css selectors, must utilize css stylesheet accomplish functionality (or utilize inline lookups, not advisable) - style sheet best solution anyway.
see @icza's reply understand why trying set -fx-strikethrough
style straight on button not work.
here sample application:
import javafx.application.application; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.layout.stackpane; import javafx.stage.stage; public class strikeout extends application { @override public void start(stage stage) throws exception { button strikethrough = new button("strikethrough"); strikethrough.getstylesheets().addall(getclass().getresource( "strikethrough.css" ).toexternalform()); stackpane layout = new stackpane( strikethrough ); layout.setpadding(new insets(10)); stage.setscene(new scene(layout)); stage.show(); } public static void main(string[] args) { launch(args); } }
java css javafx
No comments:
Post a Comment