Closing a dialog with a button

121 views Asked by At

I have a JFrame that calls a new JDialog, this JDialog has a button for closing it.

The JFrame should be repainted when the JDialog is closed. But when I close the JDialog with the button nothing happens, that doesn't happen when I close with the classic "X" button.

This is the windowListener from the JFrame:

private void ButtonNewMermaActionPerformed(java.awt.event.ActionEvent evt) {   

            addNewMerma dialog = new addNewMerma(new javax.swing.JFrame(), true);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    repaintTable();
                }
            });
            dialog.setVisible(true);

}         

And here the code from the button in the JDialog that closes the JDialog:

private void ButtonAddAndCloseActionPerformed(java.awt.event.ActionEvent evt) {  
            addMerma();                                           
            this.dispose();
}       

like I said the JFrame in the listener need to capture when the JDialog is closed and repaint the Jframe. But when i close with the button (ButtonAddAndClose) nothing happens.

1

There are 1 answers

0
Carlos Herrera Plata On BEST ANSWER

OK i found the solution by chance. I added in the button this code:

private void ButtonAddAndCloseActionPerformed(java.awt.event.ActionEvent evt) {  
        addMerma();    
        (this.getWindowListeners()[0]).windowClosing(null);                                       
        this.dispose();

}

that was the solution, i don't kow if is correct but works jajaja, I'll leave this here if somebody has the same problem.