什么是java.awt.Component.getName()和setName()用于? [英] What is java.awt.Component.getName() and setName() used for?

查看:351
本文介绍了什么是java.awt.Component.getName()和setName()用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是<一个href=\"http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#getName%28%29\"><$c$c>java.awt.Component.getName()用于?它似乎总是在我建立与NetBeans的应用程序。我想存储它每个组件的一些帮助文本 - 我不希望使用的提示,我还有一个面板,我将展示的帮助文本

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(..)在JDK大多采用由外观实现类设置ID,例如字符串为每个组件,例如BasicOptionPaneUI可以称之为一个按钮组件上,它的名称设置为OptionPane.button。

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".

行getName()进行toString()方法,设置复合/父Component AWT内部和子组件和Swing调试日志记录code的姓名或名称。
我强烈怀疑getName()方法也使用一些AWT / Swing的测试框架。

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.

所以,如果你不依赖于任何的getName()的上述用途,您可以尝试使用它的帮助信息,虽然我不会推荐它。

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.

也许你应该重新考虑你的设计?使用名称做一些查找在从资源包加载帮助文本一个HashMap?

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?

这篇关于什么是java.awt.Component.getName()和setName()用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆