改进的模式对话框 : 模式 « Swing « Java 教程

En
Java 教程
1. 语言基础
2. 数据类型
3. 操作符
4. 流程控制
5. 类定义
6. 开发相关
7. 反射
8. 正则表达式
9. 集合
10. 线
11. 文件
12. 泛型
13. 本土化
14. Swing
15. Swing事件
16. 二维图形
17. SWT
18. SWT 二维图形
19. 网络
20. 数据库
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web服务SOA
27. EJB3
28. Spring
29. PDF
30. 电子邮件
31. 基于J2ME
32. J2EE应用
33. XML
34. 设计模式
35. 日志
36. 安全
37. Apache工具
38. 蚂蚁编译
39. JUnit单元测试
Java
Java 教程 » Swing » 模式 
14. 75. 2. 改进的模式对话框

Mustang introduces different types of modality, in which you no longer use setModal but the new method setModalityType in the Dialog class to make a dialog modal.

Dialog.ModalityType is an enum in the java.awt package.

Its values are as follows:

  1. APPLICATION_MODAL. Blocks all windows in the same application except those with the modal dialog as their owner.
  2. DOCUMENT_MODAL. Makes all windows from the same document inaccessible, except those from the modal dialog's child hierarchy.
  3. MODELESS. Does not block any other windows.
  4. TOOLKIT_MODAL. Makes all windows from the same toolkit inaccessible, except those from the modal dialog's child hierarchy.
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class ApplicationModalDialogDemo {

  public static void main(String[] args) {
    final JFrame parent1 = new JFrame("Parent Frame 1");
    parent1.setLayout(new FlowLayout());
    parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Application modal dialog");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        JDialog dialog = new JDialog(parent1, "Application-Modal Dialog",
            Dialog.ModalityType.APPLICATION_MODAL);
        dialog.setBounds(200150200150);
        dialog.setVisible(true);
      }
    });
    parent1.add(button);
    parent1.setBounds(100100200150);
    parent1.setVisible(true);

    JFrame parent2 = new JFrame("Parent Frame 2");
    parent2.setBounds(500100200150);
    parent2.setVisible(true);
  }
}
14. 75. 模式
14. 75. 1. Four new AWT modality models introduced with the Java Mustang release.
14. 75. 2. 改进的模式对话框
14. 75. 3. Dialog.ModalityType.DOCUMENT_MODAL
14. 75. 4. 模态对话框
14. 75. 5. 使用方式排斥
14. 75. 6. 展示模式类型
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.