正如您从上述主题中看到的那样,
我想知道如何解除由于另一个JOptionPane而变得不相关的JOptionPane,并且因为用户,出于某种原因,并没有通过他自己点击确定按钮来解除第一个按钮(例如)。如何在GUI中出现另一个JOptionPane时关闭一个JOptionPane
我已经看到了在其他网站类似的问题的一些洁具,人们建议简单地做:
JOptionPane.getRootFrame().dispose();
但我怎么能存储每个JOptionPane的我,并能够只辞退参考想要一个。
感谢
编辑:
代码示例:
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
}
一个JOptionPane的通常模态(当然有例外),所以我不知道用户如何甚至能够打开第二JOptionPane的时候,第一个是可见的?您是否可以创建并发布一个小型可编译和可运行的程序来演示您的问题,并且可以测试,修改和更正[sscce](http://sscce.org)? –
好吧我已经生成了真正简单的工作示例,我应该在哪里上传它? – JavaSa
@JavaSa:编辑您的文章并加入。 –