2016-05-07 5 views
0

項目メニューAboutあなたは以下を参照することができますとしてではなく、ボタンのおかげで閉じることができJDialog次のとおりです。私はJDialogの閉じるボタンをクリックしたときJDialogをボタンで閉じる?私<code>JFrame</code>の

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {           
    aboutDialog.this.dispose(); 
}         

は時々、それが実際に閉じプログラム全体。

私が試した:

aboutDialog.this.setvisible(true) 
aboutDialog.this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
aboutDialog.this.setDefaultCloseOperation(HIDE_ON_CLOSE); 
aboutDialog.this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); 
をしかし、それは、任意のアイデアを働いていませんでしたか?

+0

aboutDialog.this.setDefaultCloseOperation(EXIT_ON_CLOSE)? – MadProgrammer

+0

'JDialogの閉じるボタンをクリックすると、プログラム全体が閉じられることがあります。 ' - ダイアログがアプリケーションの唯一の開いているウィンドウである場合に発生します。 – camickr

答えて

0

重複:Button for closing a JDialog {

import java.awt.event.*; 
    import javax.swing.*; 

    public class YourDialog extends JDialog implements ActionListener{ 

     JButton button; 

     public YourDialog() { 
     button = new JButton("Close"); 
     button.addActionListener(this); 
     add(button); 
     pack(); 
     setVisible(true); 
     } 

     public void actionPerformed(ActionEvent e) { 
      dispose(); 
     } 
    } 
} 
関連する問題