my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes joptionpane problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "joptionpane problems" Watch "joptionpane problems" New topic
Author

joptionpane problems

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I have a JOptionPane whose buttons are not respond quite right. Lets say I hit No the next time the JOptionPane comes up again I cannot hit on No again but I can hit on either Yes or Cancel. And the same problem happens with the other buttons. If I no hit Yes the next time around I cannot hit on Yes again

final JOptionPane optionPane = new JOptionPane(
"The xxxxx has changed.\n Do you want to save the changes?",
JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_CANCEL_OPTION);
dialog = new JDialog(frame,true);
dialog.setFont(font);
dialog.setContentPane(optionPane);
optionPane.addPropertyChangeListener(
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e)
{
String prop = e.getPropertyName();
System.out.println("propertyChange " + prop);
if(dialog.isVisible() && (e.getSource() == optionPane)
&& (prop.equals(JOptionPane.VALUE_PROPERTY) ||
prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
if(optionPane.getValue() instanceof Integer)
{
int value = ((Integer)optionPane.getValue()).intValue();
if (value == JOptionPane.YES_OPTION)
{
....
}
else if (value == JOptionPane.NO_OPTION)
{
....
}
else if(value == JOptionPane.CANCEL_OPTION)
{
....
}
}
else
dialog.setVisible(false);
}
}
});
dialog.pack();
dialog.setLocationRelativeTo(frame);

Thank you
[ June 21, 2005: Message edited by: john mattucci ]
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
hi john,

you have added "PropertyChangeListener" to the optionpane, so it will call propertyChange() method when you clicked on another button. in my opinion there are two ways to overcome from this problem.

1. insatiate your dialog box and option pane each time when it should display, so that each dialog is new one and each button

2. otherwise, change the optionpane value by your self in propertyChange() method.
example

Hope This Helps.
All The Best
[ June 22, 2005: Message edited by: sasi kala ]
 
wood burning stoves
 
subject: joptionpane problems