swing Top-Level Containers 组成

Swing的顶级容器包括 JFrame、JDialog 和 JWindow,每个GUI组件只能在一个容器中出现。可选地,顶级容器可以添加菜单栏。Frame示例包含绿色菜单栏和黄色标签。根面板作为中间容器管理内容面板和菜单栏,具有玻璃面板、分层面板、内容面板和可选菜单栏四个部分。
摘要由CSDN通过智能技术生成

generally useful top-level container classes: JFrame, JDialog, and JApplet.

l         Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.

l         You can optionally add a menu bar to a top-level container

The frame contains a green menu bar (with no menus) and, in the frame's content pane, a large blank, yellow label

 
frame.setJMenuBar(greenMenuBar);
 

The Root Pane

 

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.

Here's a list of the components that a root pane provides to a frame (and to every other top-level container):

 

 

As the preceding figure shows, a root pane has four parts:

1.         The glass pane

Hidden, by default. If you make the glass pane visible, then it's like a sheet of glass over all the other parts of the root pane. It's completely transparent unless you implement the glass pane's paintComponent method so that it does something, and it can intercept input events for the root pane. In the next section, you'll see an example of using a glass pane.

2.         The layered pane

Serves to position its contents, which consist of the content pane and the optional menu bar. Can also hold other components in a specified Z order. For information, see The Layered Pane.

3.         The content pane

The container of the root pane's visible components, excluding the menu bar. For information on using the content pane, see Using Top-Level Containers.

4.         The optional menu bar

The home for the root pane's container's menus. If the container has a menu bar, you generally use the container's setJMenuBar method to put the menu bar in the appropriate place. For more information on using menus and menu bars, see How to Use Menus.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值