swing 父窗口的一个按钮打开子窗口(jdialog) 子窗口不关闭的情况下 怎么让父窗口可用??

解决方案 »

  1.   

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    public class TestMode extends JFrame implements ActionListener{ JDialog dialog;

    public TestMode(){
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton b = new JButton();
    b.addActionListener(this);

    getContentPane().add(b);
    setSize(100,100);
    }

    public static void main(String[] args){
    TestMode frame = new TestMode();
    frame.setVisible(true);
    } public void actionPerformed(ActionEvent e) {
    if(dialog == null){
    dialog = new JDialog(this, true);
    JButton b = new JButton();
    b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    //需要隐藏再显示,以便释放锁
    dialog.setVisible(false);
    dialog.setModal(false);
    dialog.setAlwaysOnTop(true);
    dialog.setVisible(true);
    }
    });
    dialog.add(b);
    dialog.setSize(100,100);
    }
    dialog.setVisible(true);
    }
    }