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

Is there a best practices for storing UI settings in a file?

c# user-interface settings configuration-files

I have not seeing an satisfactory answer for this yet, so thought I'd ask. Are there any best practices for storing UI settings in a file?

How to make a Button clickable only once in a day

android button click

i have a button through which a customer can claim his daily rewards. i want that button to be clicked only once a day. how could i do this?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.