I'm no Java guy, but I believe setName()
and getName()
could be used for this. Perhaps double-check that these aren't used internally.
What is the equivalent of the Objective-C 'tag' property in Java ?
-
12-12-2021 - |
Domanda
So I have two JSliders each of which invokes the stateChanged() method and I want to figure out which of the sliders invokes it.
In Objective-C, I used to use the tag property to differentiate which is which. Is there such an equivalent in Java ?
Soluzione
Altri suggerimenti
Tags are not normally used when determining the source component. You could use ChangeEvent.getSource()
derived from the EventObject
public void stateChanged(ChangeEvent event) {
JSlider source = (JSlider)event.getSource();
...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow