-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0, 1.2.1, 1.3.0
-
beta
-
generic, x86
-
generic, solaris_2.6, windows_nt
The following code demonstrates a problem with hiding and then showing a JDialog that has been created by JOptionPane.createDialog. The applet has 1 button. Press that button to have a dialog popped up. Once that dialog is visible, you can dismiss it by pressing 1 of any 3 buttons. The dialog will then be dismissed and you can press the applet's dialog again. Once the dialog is visible again, press the same button you pressed last time and you'll notice that nothing happens. Press any of the other 2 buttons though and it will dismiss itself. Follow the same steps and you'll notice that each time, the last button to be pressed does not work.
java full version "JDK-1.2-V"
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.beans.*;
public class Applet1 extends JApplet {
static Applet1 applet1;
boolean isStandalone = false;
Container contentPane;
BorderLayout borderLayout = new BorderLayout();
JPanel jPanel = new JPanel(new GridBagLayout());
JPanel promiseDatePanel = new JPanel(new GridBagLayout());
JTextField tf0 = new
JTextField("textxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
JTextField tf1 = new
JTextField("textzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
JTextField tf2 = new
JTextField("textaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
JTextField tf3 = new
JTextField("textbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
;
String htmlText =
"<html>A JLabel with <i>various <font color=blue>text styles<br>" +
"And a new line!</font></i>";
JLabel msgsLabel = new JLabel(htmlText);
JList msgsList = new JList(new String[] {"message1","message2"});
JSeparator separator = new JSeparator();
JLabel datesLabel = new JLabel("The dates below are valid for this order:");
JList datesList = new JList(new String[] {"1999-Jan-01 Optimal Promise Date",
"1999-Jan-01 Requested Promise Date", "1999-Jan-01 Next Available Date"});
JButton promiseButton = new JButton("promise");
public Applet1() {
}
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
applet1 = this;
contentPane = this.getContentPane();
setSize(new Dimension(800, 600));
contentPane.setLayout(new BorderLayout());
contentPane.add(jPanel, BorderLayout.CENTER);
contentPane = this.getContentPane();
contentPane.add(jPanel);
promiseButton.addActionListener(new ActionListener()
{
//to detect pulldown; invoked on both! coordinate with another event to
//prevent action when pulldown disappears?
public void actionPerformed(ActionEvent e) {
promise();
}
});
{ OrdGBConstraints c = new OrdGBConstraints();
jPanel.add(promiseButton, c); c.gridy++;
}
//Promise Date Panel
{ OrdGBConstraints c = new OrdGBConstraints();
promiseDatePanel.add(tf0, c); c.gridy++;
promiseDatePanel.add(tf1, c); c.gridy++;
promiseDatePanel.add(tf2, c); c.gridy++;
promiseDatePanel.add(tf3, c); c.gridy++;
c.fill=c.HORIZONTAL;
promiseDatePanel.add(msgsLabel, c); c.gridy++;
promiseDatePanel.add(msgsList, c); c.gridy++;
promiseDatePanel.add(separator, c); c.gridy++;
promiseDatePanel.add(datesLabel, c); c.gridy++;
promiseDatePanel.add(datesList, c);
}
datesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private JDialog dialog = null;
private JOptionPane pane = null;
void promise()
{
if(dialog == null)
{
pane = new JOptionPane();
pane.setMessage(promiseDatePanel);
String changeDate = "Change Promise Date",
changeDateAndConsume = "Change Promise Date and Consume",
close = "Close";
pane.setOptions(new String[] {changeDate, changeDateAndConsume, close});
dialog = pane.createDialog(contentPane, "my title");
dialog.pack();
}
// pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
dialog.setVisible(true);
}
public String getAppletInfo() {
return "Applet Information";
}
public String[][] getParameterInfo() {
return null;
}
}
class OrdGBConstraints extends GridBagConstraints {
OrdGBConstraints() {
gridx=0; gridy=0; gridwidth=1; gridheight=1; weightx=1.0; weighty=1.0;
anchor=GridBagConstraints.WEST; fill=GridBagConstraints.NONE;
insets=new Insets(10,0,0,0); ipadx=0; ipady=0;
}
}
Name: krT82822 Date: 02/19/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
When a dialog is created from a JOptionPane instance, and the dialog is reused,
the OK button functions properly the odd times, and does not hde the dialog at
even times.
It appears to me different events are generated when clicking the button (?)
might be related to bug 4245937
Here is a self containing app for demo, it shows the dialog 5 times, 2 and 4
don't close with the button.
import javax.swing.*;
/**
* sdk version:
* java version "1.3.0rc1"
* Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
* Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
* @author: M.Meyers
**/
public class OptionPaneBug extends JOptionPane{
JDialog dlg;
Object[] msg = {"Some text","goes here"};
public OptionPaneBug(){
super(null,JOptionPane.QUESTION_MESSAGE);
setMessage(msg);
}
public void showIt(){
if(dlg==null){
dlg=createDialog(null,"Bugged dialog");
}
dlg.setVisible(true);
}
public static void main(String[] args){
OptionPaneBug instance = new OptionPaneBug();
for(int i=0;i<5;i++){
instance.showIt();
}
System.exit(0);
}
}
(Review ID: 101320)
======================================================================
java full version "JDK-1.2-V"
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.beans.*;
public class Applet1 extends JApplet {
static Applet1 applet1;
boolean isStandalone = false;
Container contentPane;
BorderLayout borderLayout = new BorderLayout();
JPanel jPanel = new JPanel(new GridBagLayout());
JPanel promiseDatePanel = new JPanel(new GridBagLayout());
JTextField tf0 = new
JTextField("textxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
JTextField tf1 = new
JTextField("textzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
JTextField tf2 = new
JTextField("textaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
JTextField tf3 = new
JTextField("textbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
;
String htmlText =
"<html>A JLabel with <i>various <font color=blue>text styles<br>" +
"And a new line!</font></i>";
JLabel msgsLabel = new JLabel(htmlText);
JList msgsList = new JList(new String[] {"message1","message2"});
JSeparator separator = new JSeparator();
JLabel datesLabel = new JLabel("The dates below are valid for this order:");
JList datesList = new JList(new String[] {"1999-Jan-01 Optimal Promise Date",
"1999-Jan-01 Requested Promise Date", "1999-Jan-01 Next Available Date"});
JButton promiseButton = new JButton("promise");
public Applet1() {
}
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
applet1 = this;
contentPane = this.getContentPane();
setSize(new Dimension(800, 600));
contentPane.setLayout(new BorderLayout());
contentPane.add(jPanel, BorderLayout.CENTER);
contentPane = this.getContentPane();
contentPane.add(jPanel);
promiseButton.addActionListener(new ActionListener()
{
//to detect pulldown; invoked on both! coordinate with another event to
//prevent action when pulldown disappears?
public void actionPerformed(ActionEvent e) {
promise();
}
});
{ OrdGBConstraints c = new OrdGBConstraints();
jPanel.add(promiseButton, c); c.gridy++;
}
//Promise Date Panel
{ OrdGBConstraints c = new OrdGBConstraints();
promiseDatePanel.add(tf0, c); c.gridy++;
promiseDatePanel.add(tf1, c); c.gridy++;
promiseDatePanel.add(tf2, c); c.gridy++;
promiseDatePanel.add(tf3, c); c.gridy++;
c.fill=c.HORIZONTAL;
promiseDatePanel.add(msgsLabel, c); c.gridy++;
promiseDatePanel.add(msgsList, c); c.gridy++;
promiseDatePanel.add(separator, c); c.gridy++;
promiseDatePanel.add(datesLabel, c); c.gridy++;
promiseDatePanel.add(datesList, c);
}
datesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
private JDialog dialog = null;
private JOptionPane pane = null;
void promise()
{
if(dialog == null)
{
pane = new JOptionPane();
pane.setMessage(promiseDatePanel);
String changeDate = "Change Promise Date",
changeDateAndConsume = "Change Promise Date and Consume",
close = "Close";
pane.setOptions(new String[] {changeDate, changeDateAndConsume, close});
dialog = pane.createDialog(contentPane, "my title");
dialog.pack();
}
// pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
dialog.setVisible(true);
}
public String getAppletInfo() {
return "Applet Information";
}
public String[][] getParameterInfo() {
return null;
}
}
class OrdGBConstraints extends GridBagConstraints {
OrdGBConstraints() {
gridx=0; gridy=0; gridwidth=1; gridheight=1; weightx=1.0; weighty=1.0;
anchor=GridBagConstraints.WEST; fill=GridBagConstraints.NONE;
insets=new Insets(10,0,0,0); ipadx=0; ipady=0;
}
}
Name: krT82822 Date: 02/19/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
When a dialog is created from a JOptionPane instance, and the dialog is reused,
the OK button functions properly the odd times, and does not hde the dialog at
even times.
It appears to me different events are generated when clicking the button (?)
might be related to bug 4245937
Here is a self containing app for demo, it shows the dialog 5 times, 2 and 4
don't close with the button.
import javax.swing.*;
/**
* sdk version:
* java version "1.3.0rc1"
* Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
* Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
* @author: M.Meyers
**/
public class OptionPaneBug extends JOptionPane{
JDialog dlg;
Object[] msg = {"Some text","goes here"};
public OptionPaneBug(){
super(null,JOptionPane.QUESTION_MESSAGE);
setMessage(msg);
}
public void showIt(){
if(dlg==null){
dlg=createDialog(null,"Bugged dialog");
}
dlg.setVisible(true);
}
public static void main(String[] args){
OptionPaneBug instance = new OptionPaneBug();
for(int i=0;i<5;i++){
instance.showIt();
}
System.exit(0);
}
}
(Review ID: 101320)
======================================================================
- duplicates
-
JDK-4230329 JOptionPane PropertyChangeListener not called when same button is pressed twice
-
- Closed
-