个性化阅读
专注于IT技术分析

Java JRootPane

点击下载

JRootPane是JFrame, JDialog, JWindow, JApplet和JInternalFrame在后台使用的轻量级容器。

嵌套类

修饰符和类型 描述
protected class JRootPane.AccessibleJRootPane 此类实现JRootPane类的可访问性支持。
受保护的阶级 JRootPane.RootLayout 一个自定义布局管理器, 它负责layeredPane, glassPane和menuBar的布局。

领域

修饰符和类型 领域 描述
static int COLOR_CHOOSER_DIALOG 用于windowDecorationStyle属性的常数。
受保护的JButton contentPane 内容窗格。
protected Container defaultButton 当窗格具有焦点并发生特定于UI的操作(例如按Enter键)时, 将激活该按钮。
受保护的JMenuBar menuBar 菜单栏。
protected Component glassPane 覆盖在菜单栏和内容窗格上的玻璃窗格, 因此它可以拦截鼠标的移动等。
static int ERROR_DIALOG 用于windowDecorationStyle属性的常数。

建设者

建设者 描述
JRootPane() 创建一个JRootPane, 设置其glassPane, layeredPane和contentPane。

有用的方法

修饰符和类型 方法 描述
protected void addImpl(Component comp, Object constraints, int index) 重写以强制将玻璃组件的位置设置为零子级。
void addNotify() 通知此组件它现在具有父组件。
protected Container createContentPane() 构造函数方法调用它来创建默认的contentPane。
protected Component createGlassPane() 它由构造函数方法调用以创建默认的glassPane。
AccessibleContext getAccessibleContext() 它获取与此JRootPane关联的AccessibleContext。
JButton getDefaultButton() 它返回defaultButton属性的值。
void setContentPane(Container content) 它设置内容窗格-包含由根窗格作为父级的组件的容器。
void setDefaultButton(JButton defaultButton) 它设置defaultButton属性, 该属性确定此JRootPane的当前默认按钮。
void setJMenuBar(JMenuBar menu) 它添加或更改在分层窗格中使用的菜单栏。

JRootPane示例

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;

public class JRootPaneExample {
	 public static void main(String[] args) {
		    JFrame f = new JFrame();
		    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		    JRootPane root = f.getRootPane();

		    // Create a menu bar
		    JMenuBar bar = new JMenuBar();
		    JMenu menu = new JMenu("File");
		    bar.add(menu);
		    menu.add("Open");
		    menu.add("Close");
		    root.setJMenuBar(bar);

		    // Add a button to the content pane
		    root.getContentPane().add(new JButton("Press Me"));

		    // Display the UI
		    f.pack();
		    f.setVisible(true);
		  }
}

输出量

Java JRootpane
赞(0)
未经允许不得转载:srcmini » Java JRootPane

评论 抢沙发

评论前必须登录!