Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

joptionpane problems

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic