2.3 各种容器面板和组件
2.3.1. 根面板(JRootPane)
根面板由一个玻璃面板(glassPane)、一个内容面板(contentPane)和一个可选择的菜单条(JMenuBar)组成,而内容面板和可选择的菜单条放在同一分层。玻璃面板是完全透明的,缺省值为不可见,为接收鼠标事件和在所有组件上绘图提供方便。 根面板提供的方法:
- Container getContentPane(); //获得内容面板
- setContentPane(Container); //设置内容面
- JMenuBar getMenuBar( ); //活动菜单条
- setMenuBar(JMenuBar); //设置菜单条
- JLayeredPane getLayeredPane(); //获得分层面板
- setLayeredPane(JLayeredPane); //设置分层面板
- Component getGlassPane(); //获得玻璃面板
- setGlassPane(Component); //设置玻璃面板
2.3.2 分层面板(JLayeredPane)
Swing提供两种分层面板:JlayeredPane和JDesktopPane。 JDesktopPane是JLayeredPane的子类,专门为容纳内部框架(JInternalFrame)而设置。 向一个分层面板种添加组件,需要说明将其加入哪一层,指明组件在该层中的位置:add(Component c, Integer Layer, int position)。
2.3.3 面板(JPanel)