in java swing
possible put menu on right side of menu bar using:
menubar.add(menu1); menubar.add(box.createhorizontalglue()); menubar.add(menu2);
this put menu1
on left , menu2
on right. function (obviously) not available in javafx
.
in javafx
, have seen same can achieved toolbar using:
final pane rightspacer = new pane(); hbox.sethgrow( rightspacer, priority.sometimes );
although, workaround not usuable menus.
question: there way create right spacer menus in javafx
?
one slightly-hacky way use 2 menu bars in hbox
. can give spacer separating them same style menu bar adding menu-bar
style class it:
import javafx.application.application; import javafx.scene.scene; import javafx.scene.control.menu; import javafx.scene.control.menubar; import javafx.scene.layout.borderpane; import javafx.scene.layout.hbox; import javafx.scene.layout.priority; import javafx.scene.layout.region; import javafx.stage.stage; public class menualignment extends application { @override public void start(stage primarystage) { menubar leftbar = new menubar(); leftbar.getmenus().addall(new menu("file"), new menu("edit")); menubar rightbar = new menubar(); rightbar.getmenus().addall(new menu("help")); region spacer = new region(); spacer.getstyleclass().add("menu-bar"); hbox.sethgrow(spacer, priority.sometimes); hbox menubars = new hbox(leftbar, spacer, rightbar); borderpane root = new borderpane(); root.settop(menubars); scene scene = new scene(root, 600, 600); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }
a potential disadvantage of approach couldn't use system menu bar.
Comments
Post a Comment