File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "joptionpane problems" Watch "joptionpane problems" New topic

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?",
dialog = new JDialog(frame,true);
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)

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.

Hope This Helps.
All The Best
[ June 22, 2005: Message edited by: sasi kala ]
I agree. Here's the link:
subject: joptionpane problems
It's not a secret anymore!