setname java,什么是java.awt.Component.getName()和setName()用于?

Java的awt.Component.getName()方法主要用于设置组件的标识字符串,常用于内部实现和调试。该方法在一些测试框架中可能也有用途。然而,在你构建的应用中,getName()总是返回null。考虑存储帮助文本时,不推荐直接使用getName(),而建议重新评估设计,可能可以利用这个名字来在哈希映射中查找资源包加载的帮助文本。
摘要由CSDN通过智能技术生成

What is java.awt.Component.getName() used for? It always seems to be null in the applications I build with NetBeans. I'm thinking of storing some help text per component in it -- I don't want to use the tooltip, I have another panel where I'll show the help text.

解决方案

Component.setName(..) is used in the JDK mostly by the look and feel implementation classes to set ID-like strings for each component, e.g. BasicOptionPaneUI might call it on a button component to set its name to "OptionPane.button".

The getName() is used in toString() methods, when setting the names of child components inside a Composite/parent Component and in AWT and Swing debug logging code.

I suspect strongly that the getName() method is also used by some AWT/Swing testing frameworks.

So if you're not dependent on any of the above uses of getName(), you might try using it for your help messages, though I would not recommend it.

Maybe you should reconsider your design? Use the name to do some lookup in a hashmap that loads the help text from a resource bundle?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值