--- a/jdk/src/share/classes/javax/swing/JOptionPane.java Sat Mar 05 20:54:53 2011 -0800
+++ b/jdk/src/share/classes/javax/swing/JOptionPane.java Mon Mar 14 15:01:53 2011 +0300
@@ -987,11 +987,33 @@
}
dialog.pack();
dialog.setLocationRelativeTo(parentComponent);
+
+ final PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ // Let the defaultCloseOperation handle the closing
+ // if the user closed the window without selecting a button
+ // (newValue = null in that case). Otherwise, close the dialog.
+ if (dialog.isVisible() && event.getSource() == JOptionPane.this &&
+ (event.getPropertyName().equals(VALUE_PROPERTY) ||
+ event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) &&
+ event.getNewValue() != null &&
+ event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
+ dialog.setVisible(false);
+ }
+ }
+ };
+
WindowAdapter adapter = new WindowAdapter() {
private boolean gotFocus = false;
public void windowClosing(WindowEvent we) {
setValue(null);
}
+
+ public void windowClosed(WindowEvent e) {
+ removePropertyChangeListener(listener);
+ dialog.getContentPane().removeAll();
+ }
+
public void windowGainedFocus(WindowEvent we) {
// Once window gets focus, set initial focus
if (!gotFocus) {
@@ -1008,20 +1030,8 @@
setValue(JOptionPane.UNINITIALIZED_VALUE);
}
});
- addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent event) {
- // Let the defaultCloseOperation handle the closing
- // if the user closed the window without selecting a button
- // (newValue = null in that case). Otherwise, close the dialog.
- if (dialog.isVisible() && event.getSource() == JOptionPane.this &&
- (event.getPropertyName().equals(VALUE_PROPERTY) ||
- event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) &&
- event.getNewValue() != null &&
- event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
- dialog.setVisible(false);
- }
- }
- });
+
+ addPropertyChangeListener(listener);
}