简体   繁体   English

如何将菜单栏添加到选项卡式窗格?

[英]How do I add a menubar to a tabbed pane?

Is it possible to add a menubar to one of the windows in a tabbed pane? 是否可以在选项卡式窗格的窗口之一中添加菜单栏? And is a frame the only container which can have a menubar? 框架是唯一可以带有菜单栏的容器吗?

As Suraj mentioned, you can force the issue as as they are both, both components and containers however you will have to do the extra work to organize it in your pane's layout along with the rest of the components in the pane -- unlike with a JFrame which has methods to support it outright (setJMenuBar and you're outta there). 正如Suraj提到的那样,您可以强制问题同时发生,因为它们既是组件又是容器,但是您必须做额外的工作才能将其与窗格中的其余组件一起组织在窗格的布局中-与JFrame具有完全支持它的方法(setJMenuBar,您已经不在了)。 Normally, when added to a JFrame, the JMenuBar is not in the content pane, it is in a layered pane which contains both the menu bar and the content pane below it. 通常,添加到JFrame时,JMenuBar不在内容窗格中,而是在分层的窗格中,该窗格同时包含菜单栏和其下方的内容窗格。

You might also want to consider using a JToolBar which is very flexible (more easily customized) and has some optional built-in goodies like being separable/dockable. 您可能还需要考虑使用JToolBar,它非常灵活(更易于自定义),并且具有一些可选的内置功能,例如可分离/可停靠。

Though you can directly add a JMenubar in to a JtabbedPane as both are JComponents. 尽管您可以直接将JMenubar添加到JtabbedPane中,因为两者都是JComponents。 But it wont look nice(usable), if you have tried it. 但是,如果您尝试过的话,它看起来不会很好(可用)。

I would suggest to subclass BasicTabbedPaneUI and override installComponents(), there you can add you JmenuBar at the top or wherever you want. 我建议子类化BasicTabbedPaneUI并重写installComponents(),在那里您可以在顶部或所需的任何位置添加JmenuBar。

Is it possible to add a menubar to one of the windows in a tabbed pane? 是否可以在选项卡式窗格的窗口之一中添加菜单栏?

What problem did you have when you tried to do this? 尝试执行此操作时遇到什么问题?

If you need more help post your SSCCE showing the problem. 如果您需要更多帮助,请发布SSCCE显示问题。

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

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