Question

Is there anyway to add an ID or a unique identifier to a JLabel?

Thanks all

Was it helpful?

Solution

JLabel has a setName method that is inherited from java.awt.Component. You could use this for an ID.

OTHER TIPS

You can call Component.setName on it, or JComponent.putClientProperty, or subclass or use the JLabel object as a key is a Map of some sort.

But probably the way to go is to keep hold of a reference to the original object, so you can write clean, direct code that doesn't have to look the component up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top