Closing a dialog with a button

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.

Answers


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.


Need Your Help

What is the correct way to make a Material Design Lite table 100% width?

html css material-design-lite

I'm looking into using Google's Material Design Lite framework and I'm wondering how I can make a table span a 100% width of it's containing element: