java - How to modify MenuButton arrow color by JavaFX not FXML CSS? -
i trying modify color of menubutton
arrow , using javafx
code not css
.
i found inside caspian.css
:
.menu-button > .arrow-button > .arrow { -fx-background-insets: 1 0 -1 0, 0; -fx-background-color: -fx-mark-highlight-color, -fx-mark-color; -fx-padding: 0.25em; /* 3 */ -fx-shape: "m 0 -3.5 v 7 l 4 -3.5 z"; }
i tried use :
menubutton.lookup(".arrow");
but throw nullpointerexception
and when :
system.out.println(this.getstyleclass().tostring());
it out put only: menu-button
only.
so can 1 give me way modify using java without using css ??
this works:
import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.menubutton; import javafx.scene.control.menuitem; import javafx.scene.layout.stackpane; import javafx.stage.stage; public class redmenubutton extends application { @override public void start(stage primarystage) { final stackpane root = new stackpane(); final menubutton menubutton = new menubutton("menu"); menubutton.getitems().addall(new menuitem("item 1"), new menuitem("item 2"), new menuitem("item 3")); root.getchildren().add(menubutton); final scene scene = new scene(root, 250, 150); primarystage.setscene(scene); primarystage.show(); menubutton.lookup(".arrow").setstyle("-fx-background-color: red;"); } public static void main(string[] args) { launch(args); } }
update: better solution (which have got first time if daylight savings hadn't messed sleep ;)).
import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.menubutton; import javafx.scene.control.menuitem; import javafx.scene.layout.stackpane; import javafx.stage.stage; public class redmenubutton extends application { @override public void start(stage primarystage) { final stackpane root = new stackpane(); final menubutton menubutton = new menubutton("menu"); menubutton.getitems().addall(new menuitem("item 1"), new menuitem("item 2"), new menuitem("item 3")); root.getchildren().add(menubutton); menubutton.setstyle("-fx-mark-color: red"); final scene scene = new scene(root, 250, 150); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }
Comments
Post a Comment