How would I get the text of a JLabel (with an icon) explaining what the label is by hovering over the label?

荒凉一梦 提交于 2019-12-02 00:56:51

问题


I want to see the text of JLabel when I hover over the label. The text explains what the label does in detail.


回答1:


You would need to set the text of the tooltip by calling: setToolTipText()

More about tooltips in the tutorial: http://download.oracle.com/javase/tutorial/uiswing/components/tooltip.html




回答2:


If you want to retrieve the Tooltip then you should use something like this:

JLabel label;
...//initialize label, etc
String text = label.getToolTipText();

In case you are asking how to set the Tooltip then you should do the opposite:

JLabel label;
...//initialize label, etc
label.setToolTipText("this is the description of the label");


来源:https://stackoverflow.com/questions/6209514/how-would-i-get-the-text-of-a-jlabel-with-an-icon-explaining-what-the-label-is

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