• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

joptionpane problems

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic