总结:创建多个模态对话框,当关闭一个隐藏的模态对话框时,如果单击低级模态对话框,关闭的模态对话框上的模态对话框可以回到低级模态对话框。
重现问题的方法,运行应用程序->单击“按钮A”->单击“按钮B”->单击“按钮C”,如果单击对话框a,则对话框C可以返回对话框A。
请帮忙,谢谢!!
import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
public class ModalDialogProblem {
/**
* @param args
*/
public static void main(String[] args) {
JDialog a = new JDialog();
a.setTitle("Dialog A");
a.setModalityType(ModalityType.APPLICATION_MODAL);
a.setLayout(null);
a.setBounds(0, 0, 400, 300);
JButton bA = new JButton("Button A");
bA.setBounds(20, 20, 180, 40);
bA.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
final JDialog b = new JDialog();
b.setTitle("Dialog B");
b.setModalityType(ModalityType.APPLICATION_MODAL);
b.setLayout(null);
b.setBounds(40, 40, 400, 300);
JButton bB = new JButton("Button B");
bB.setBounds(20, 20, 180, 40);
bB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JDialog c = new JDialog();
c.setTitle("Dialog C");
c.setModalityType(ModalityType.APPLICATION_MODAL);
c.setLayout(null);
c.setBounds(80, 80, 400, 300);
JButton bC = new JButton("Button C");
bC.setBounds(20, 20, 180, 40);
bC.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
b.dispose();
}
});
c.add(bC);
c.setVisible(true);
}
});
b.add(bB);
b.setVisible(true);
}
});
a.add(bA);
a.setVisible(true);
}
}