Come hai visto dall'argomento sopra,
Mi piacerebbe sapere come posso eliminare un JOptionPane che è diventato irrilevante a causa di un altro JOptionPane e perché l'utente , per qualche ragione, non ha eliminato il primo da solo facendo clic sul pulsante OK (ad esempio).Come posso cancellare un JOptionPane all'emergenza di un altro JOptionPane nella GUI
Ho visto alcuni articoli in altro sito simile domanda, e la gente ha suggerito di fare semplicemente:
JOptionPane.getRootFrame().dispose();
ma come posso memorizzare un riferimento per ogni JOptionPane che ho e di essere in grado di licenziare solo voluto uno.
Grazie
Modificato:
Esempio di codice:
package Gui;
import javax.swing.JOptionPane;
import java.awt.*;
/**
*
* @author
*/
public class JpanelMainView extends javax.swing.JPanel {
/** Creates new form JpanelMainView */
public JpanelMainView() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(149, 149, 149)
.addComponent(jButton1)
.addContainerGap(178, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(77, 77, 77)
.addComponent(jButton1)
.addContainerGap(200, Short.MAX_VALUE))
);
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
JOptionPane.showMessageDialog(this, "Board was sent for validation check\n Please wait...","Board Sent",JOptionPane.INFORMATION_MESSAGE);
//Please note that this OptionPane is coming in my real program always after the first JoptionPane
//I want that if I've reached the line in the code that need to show this second JoptionPane, I will first close the first JoptionPane
//Else you will dismiss the last JoptionPane and then the first one and I don't want to give the user two JoptionPane to close, it's annoying.
JOptionPane.showMessageDialog(this, "Set your move now please","Game started",JOptionPane.INFORMATION_MESSAGE);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
Un JOptionPane di solito è modale (ci sono eccezioni, naturalmente), quindi mi chiedo come l'utente è stato anche in grado di portare una seconda JOptionPane quando il primo è visibile? Puoi creare e pubblicare un piccolo programma compilabile e eseguibile che mostri il tuo problema e che possiamo testare, modificare e possibilmente correggere, [sscce] (http://sscce.org)? –
ok ho generato un esempio di lavoro molto semplice dove dovrei caricarlo? – JavaSa
@ JavaSa: modifica il tuo post e includilo. –