简体   繁体   English

如何将JavaFX MenuBar保留在窗口的顶部

[英]How to keep JavaFX MenuBar in the top part of the window

I'm trying to make an window, where I have StackPane as root and I want to add MenuBar to this window. 我正在尝试制作一个窗口,在该窗口中我具有StackPane作为根目录,并且想要向该窗口添加MenuBar。 However MenuBar is in the center of the screen and I want to keep it in the top part of the window as in normal Windows applications. 但是,MenuBar位于屏幕的中央,我希望像通常的Windows应用程序一样将其保留在窗口的顶部。

root = new StackPane();
root.getChildren().add(new MenuBar());

this will show window like this http://i61.tinypic.com/2pzblmo.jpg 这将显示这样的窗口http://i61.tinypic.com/2pzblmo.jpg

Thanks you for your advice! 感谢您的建议!

I would say StackPane is not suitable for making a GUI including a menubar. 我会说StackPane不适合制作包含菜单栏的GUI。 StackPane will just put the controls you add to it one on top of the other. StackPane只会将您添加到其中的控件放在另一个控件之上。 In java docs you can find: "StackPane 在Java文档中,您可以找到:“ StackPane

The StackPane layout pane places all of the nodes within a single stack with each new node added on top of the previous node. StackPane布局窗格将所有节点放在单个堆栈中,每个新节点都添加到前一个节点的顶​​部。 This layout model provides an easy way to overlay text on a shape or image or to overlap common shapes to create a complex shape. 这种布局模型提供了一种简单的方法,可以在形状或图像上覆盖文本或将常见形状重叠以创建复杂的形状。 Figure 1-6 shows a help icon that is created by stacking a question mark on top of a rectangle with a gradient background. 图1-6显示了一个帮助图标,该图标是通过在带有渐变背景的矩形上方堆叠一个问号而创建的。 "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM