The problem is, the JComboBox
is using Object#equals
to compare values.
JComboBox#setSelectedIndex
is calling JComboBox#getSelectedItem
, which is using...
for (int i = 0; i < dataModel.getSize(); i++) {
E element = dataModel.getElementAt(i);
if (anObject.equals(element)) {
found = true;
objectToSelect = element;
break;
}
}
To verify that the object exists within the model before setting it.
The problem is, your proxy object is calling equals
not on the Proxy
but is invoking equals
in the object it is proxing, which ends up begin false
(because Proxy#equals(Proxy)
is more like Proxy.objectBeginProxied#equsl(Proxy)
This is actually noted in the Java Docs
An invocation of the hashCode, equals, or toString methods declared in java.lang.Object on a proxy instance will be encoded and dispatched to the invocation handler's invoke method in the same manner as interface method invocations are encoded and dispatched, as described above. The declaring class of the Method object passed to invoke will be java.lang.Object. Other public methods of a proxy instance inherited from java.lang.Object are not overridden by a proxy class, so invocations of those methods behave like they do for instances of java.lang.Object.
I'm not sure how you would fix this though