java - JavaFX style class won't refresh -
i'm adding style class node if it's selected , remove if select other item. if remove style class style wont refresh wont go normal state:
admin_category_label.getstyleclass().remove(admin_category_label.getstyleclass().indexof("selected")); admin_category_label.getstyleclass().add("clear"); but style stay same class selected
this bug. reported here removal of hovered style class, not update styling. may want vote , watch it. workaround should override css rules touched/changed same default ones. demo:
import javafx.application.application; import javafx.event.actionevent; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.control.button; import javafx.scene.control.label; import javafx.scene.layout.stackpane; import javafx.scene.layout.vboxbuilder; import javafx.stage.stage; public class styledemo extends application { @override public void start(stage primarystage) { final label lbl = new label("style me"); lbl.getstyleclass().add("style1"); // initial style button btn = new button("change style"); btn.setonaction(new eventhandler<actionevent>() { @override public void handle(actionevent arg0) { lbl.getstyleclass().remove("style1"); lbl.getstyleclass().add("style2"); } }); stackpane root = new stackpane(); root.getchildren().add(vboxbuilder.create().spacing(20).children(lbl, btn).build()); scene scene = new scene(root, 300, 250); scene.getstylesheets().add(this.getclass().getresource("style.css").toexternalform()); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } } and style.css is:
.style1 { -fx-text-fill: red; -fx-border-color: green; -fx-font-size: 20; } .style2 { -fx-text-fill: blue; -fx-border-color: red; -fx-font-size: 15; -fx-underline: true; } when button clicked added style1 removed , style2 added.
Comments
Post a Comment