Reputation: 5782
It's a little embarassing to not know how to fix this on my own, seeing how I have a bit of experience with Java, however until now I've never really done anything other than web programming with Java.
I'm trying to create a wizard, and trying to generalize creation of the fields presented in the window. As such, I don't have direct control over the actual component JTextField but a wrapper class which handles the finer details. However I would like to know when the value has changed, so I've added a "addVetoableChangeListener" method which allows me to register a VetoableChangeListener to the JTextField itself.
I've verified that the method gets called and that it passes the listener onto the JTextField in debug. However, nothing gets called. No exception is launched, and my breakpoint inside the method which implements the interface VetoableChangeListener is never called.
Is there something I'm not getting? Does the listener have to be some sort of component before it works correctly or does it simply have to implement the interface? Perhaps I'm overlooking an obvious error because I've been concentrating on it for too long, and I'm hoping it'll be evident to one of you. A simpler version of what I'm attempting is:
public class TomcatConfigPanel extends WizardKeyValuePanel implements VetoableChangeListener {
protected void initPanel(JPanel mainPanel) {
addField("port", "8080");
IWizardField portField = getField("port");
portField.addVetoableChangeListener(this);
}
public void vetoableChange(PropertyChangeEvent evt)
throws PropertyVetoException {
// Stuff that would drive you Lovecraft insane if you saw what was written here
}
}
public class WizardTextField implements IWizardField {
private JLabel label;
private JTextField field;
public WizardTextField() {
// some initialization stuff ...
}
public void addVetoableChangeListener(VetoableChangeListener listener) {
field.addVetoableChangeListener(listener);
}
}
Upvotes: 0
Views: 556
Reputation: 691655
The VetoableChangeListener will only be called if a constrained property is being changed on the JTextField. A constrained property is a property whose setter method throws a PropertyVetoException
. So, if your code never calls any such setter method on the JTextField, your listener won't ever be called. Read http://download.oracle.com/javase/tutorial/javabeans/properties/constrained.html for more details.
I haven't found any constrained property in JTextField (and in all its class hirarchy) in the API doc, so I doubt your listener could ever be called.
Upvotes: 4