What is java.awt.Component.getName() and setName() used for?

后端 未结 9 1588
半阙折子戏
半阙折子戏 2020-11-28 13:50

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 p

9条回答
  •  青春惊慌失措
    2020-11-28 13:54

    Herman Lintvelt's answer ended up being the correct one for my app.

    I created a resource bundle named HelpText.properties. It contains name=value pairs. I setName()d each of my Components with the "name" from the name=value pair. I then used a the frame's getGlassPane() to capture all mouse movements. When a mouse runs over a named component, it looks up the name in the bundle, displays help if available and forwards the mouse motion to along to the actual Component.

    • Look here for how to use the glass pane.
    • Jan Newmarch's web page on using resource bundles was very helpful.
    • Kevin Riff's response helped me figure out how to find my resource bundle.

    Whew. Only 2 days worth of dinking around. I'm finally starting to get used to Java :)

提交回复
热议问题