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.