在使用Swing设计界面时,怎么样使得跳出来的页面在控制中,其他页面失去控制权?

解决方案 »

  1.   

    是不是关于弹出对话框的问题,以下代码片断供你参考。import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;class Demo extends JFrame implements ActionListener
    {
    public JButton but = new JButton("对话框");
    public Demo()
    {
    this.getContentPane().add(but);
    this.pack();
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    but.addActionListener(this);
    }

    public static void main(String[]args)
    {
    new Demo(); 
    } public void actionPerformed(ActionEvent e) 
    {
    JDialog dialog = new JDialog();
    dialog.setSize(300,200);
    dialog.setLocationRelativeTo(null);
    dialog.setModal(true);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setAlwaysOnTop(true);
    dialog.setVisible(true);
    }
    }
      

  2.   

    JDialog dialog = new JDialog(owner,true);
    把dialog设置成模态之后,就可以实现你想要的了。