我是靠谱客的博主 聪明刺猬,最近开发中收集的这篇文章主要介绍setname java,什么是java.awt.Component.getName()和setName()用于?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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?

最后

以上就是聪明刺猬为你收集整理的setname java,什么是java.awt.Component.getName()和setName()用于?的全部内容,希望文章能够帮你解决setname java,什么是java.awt.Component.getName()和setName()用于?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部