I’m trying to prevent the user from changing a tab when the current tab is not valid.
So when he clicks on a tab, I want to check if the current one is “valid”, and if not, stay on the current tab.
I tried to use a VetoableChangeListener which didn’t work, the code never goes inside the vetoableChange method:
jTabbedPane.addVetoableChangeListener(new VetoableChangeListener() {
@Override
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
if (!isCurrentTabValid()) {
throw new PropertyVetoException("test", evt);
}
}
});
How can I do this properly?
Thanks!
A VetoableChangeListener is useful only if the class it is registered with fires a vetoable propertyChange. Most (all? never came across one) properties on JComponents and subclasses are not vetoable. Plus the selection is handled by a SingleSelectionModel, not the component itself.
That model is the hook to support vetoable changes
in code, something like