为什么JMenuBar不在JFrame内容窗格中,而JToolbar却在内容窗格中 [英] Why JMenuBar is not place in the JFrame content pane, but JToolbar place in the content pane

查看:178
本文介绍了为什么JMenuBar不在JFrame内容窗格中,而JToolbar却在内容窗格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么JMenuBar不在内容窗格中?制作Java gui程序时是否有任何原因或影响,特别是在使用jframe时? 谢谢

Why JMenuBar is not place in the content pane?is there any reason or effects when make a java gui program especially when using jframe? Thanks

推荐答案

As stated in Using Top-Level Containers article, the manu bar is managed by the Root Pane:

每个顶级容器都依赖于隐蔽的中间容器 称为根窗格.根窗格管理内容窗格,而 菜单栏,以及其他几个容器.你一般不 需要了解有关使用Swing组件的根窗格的信息.但是,如果你 曾经需要拦截鼠标单击或在多个组件上绘制, 您应该熟悉根窗格.

Each top-level container relies on a reclusive intermediate container called the root pane. The root pane manages the content pane and the menu bar, along with a couple of other containers. You generally don't need to know about root panes to use Swing components. However, if you ever need to intercept mouse clicks or paint over multiple components, you should get acquainted with root panes.

菜单栏通常位于窗口顶部,因此如果将其放置在内容窗格中,则

A menu bar is tipically placed at the top of a window, so if it would be placed in the content pane then the Layout managers would have to deal with this particular component. By segregating the menu bar from the content pane then the responsibility of laying out the menu bar and the rest of components is well divided. In addition, the menu bar location is fixed and this component is not dragabble so this can be laid out in a different way than the rest of components.

关于 JToolBar ,该组件是可拖动的,您可以可能有几个,一个放在另一个之上,然后根据需要重新排列它们的顺序.因此,此组件与菜单栏完全不同,因此可以像文本字段或其他常规组件一样将其放置在内容窗格中.

About the JToolBar this component is draggable and you may have several of them, placing one above another one and rearranging their order as you wish. So this component is totally different of a menu bar and makes sense it be placed in the content pane just as a text field or another regular component.

建议的读数:

  • Using Top-Level Containers
  • How to Use Root Panes
  • How to Use Menus

这篇关于为什么JMenuBar不在JFrame内容窗格中,而JToolbar却在内容窗格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆