开发者

JComboBox and vetoableChange?

When a user changes the value in a JComboBox, I want to prompt them to confirm the change. If they say "no," the old value will remain. If they say "yes," the new value will be selected.

I tried adding a VetoableChangeListener to the combobox, but this does not ever seem to be fired!

Per the JavaDoc for JComponent.addVetoableListener,开发者_JAVA技巧 "Adds a VetoableChangeListener to the listener list. The listener is registered for all properties."

Any idea of what is going on?

Many thanks!


Create a subclass of JComboBox and overload setSelectedItem. BEFORE setting the new value, call fireVetoableChange. If the exception is thrown, do not set the new value. If no exception is thrown, call super.setSelectedItem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜