jdialog模态化

来源:互联网 发布:linux telnet服务 编辑:程序博客网 时间:2024/06/05 06:35

  1. JButton btnNewPeople = new JButton("新建联系人");  
  2.         btnNewPeople.addActionListener(new ActionListener() {  
  3.             public void actionPerformed(ActionEvent e) {  
  4.                 NewContactWindow newContactWindow = new NewContactWindow(MainWindow.thistrue);  
  5.                 newContactWindow.setVisible(true);  
  6.             }  
  7.         });  



第一个参数为父窗口的对象,第二个参数就是是否设置模态化,在这里modal为true

然后在构造方法里可以自定义JDialog的窗口样式

[java] view plain copy
  1. public NewContactWindow(Frame parent, boolean modal) {  
  2.         super(parent, modal); 


注意:不能添加:

setAlwaysOnTop(),

setType();

this.setModalityType(ModalityType.APPLICATION_MODAL);this.setUndecorated(true);this.setModal(true);//与前面注释的super效果一样

否则会有问题出现


注意:

setVisible(true);
这个需要放在结尾

super(parent, modal);this.setTitle("质谱实验结果 ");this.setSize((int) (width * 0.85f), (int) (height * 0.9f));this.setLocationRelativeTo(null);    // 此窗口将置于屏幕的中央。this.user = user;init();setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);setVisible(true);

原创粉丝点击