How do I change the value of a JOptionPane from a PropertyChangeListener without triggering the listener?

I don't think you can do it with JOptionPane but you can using using TaskDialog framework and few others.

I don't think you can do it with JOptionPane but you can using using TaskDialog framework and few others. You can also create a dialog yourself, attach change listeners to your fields and enable/disable OK button based on content of your fields. This process is usually called "form validation.

Thanks, will use NetBeans to try this – John L. Aug 11 at 21:38.

However, I want to stop the user from closing the dialog while the text field is blank I get where you are going, but Java Swing is not very good at this. There is no way you can prevent the listener from being called. A solution would be to ignore the call, but this is complicated to implement.

The way I solved this issue is to let the pop-up disappear, check the returned value and if it is null/empty, beep and re-open it until user fills something.

JOptionPane does not internally support validation of inputs (Bug Reference). Your best bet is to create your own custom JDialog which supports disabling the OK button when the input data is invalid. I'd recommend reading the bug report since other people talk about it and give workarounds.

However, I want to stop the user from closing the dialog while the text field is blank The CustomDialog example from the section in the Swing tutorial on Stopping Automatic Dialog Closing has a working example that does this. After taking a quick look at your code and the working example I think your code should be something like: if (query.isVisible() && (e.getSource() == message) && (prop. Equals(JOptionPane.

VALUE_PROPERTY))) { if (message.getValue() == JOptionPane. UNINITIALIZED_VALUE) return; if (nameField.getText(). Equals("") && message.getValue().

Equals(JOptionPane. OK_OPTION)) { Toolkit. GetDefaultToolkit().beep(); message.

SetValue(JOptionPane. UNINITIALIZED_VALUE); } else query.dispose(); } Otherwise, I'll let you compare your code with the working code to see what the difference is.

One way to solve this problem is to add a Cancel and Ok button to your dialog. Then, disable closing the popup via the X in the corner, forcing the user to click either Cancel or Ok to finish/close the dialog. Now, simply add a listener to the text field that will disable the Ok button if the text field is blank.

Judging from your code I assume you can figure out how to implement these steps, but if you have trouble let us know! Good luck!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions