- JButton btnNewPeople = new JButton("新建联系人");
- btnNewPeople.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- NewContactWindow newContactWindow = new NewContactWindow(MainWindow.this, true);
- newContactWindow.setVisible(true);
- }
- });
第一个参数为父窗口的对象,第二个参数就是是否设置模态化,在这里modal为true
然后在构造方法里可以自定义JDialog的窗口样式
注意:不能添加:
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);