Java JLabel - add a unique identifier

落爺英雄遲暮 提交于 2019-12-24 00:19:34

问题


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

Thanks all


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/590473/java-jlabel-add-a-unique-identifier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!