【发布时间】:2012-04-27 12:01:38
【问题描述】:
如何在JButton 上获得鼠标悬停效果,这应该类似于我们将在 Stackoveflow 中的标签 鼠标悬停上获得的效果?例如
【问题讨论】:
-
这应该会给你很多答案:stackoverflow.com/search?q=[java]+mouseover
标签: java swing mouseover jbutton
如何在JButton 上获得鼠标悬停效果,这应该类似于我们将在 Stackoveflow 中的标签 鼠标悬停上获得的效果?例如
【问题讨论】:
标签: java swing mouseover jbutton
见JComponent.setToolTipText(String)。工具提示在一定程度上支持 HTML,但不支持在 SO 标记弹出窗口底部提供链接的功能。
为此,您需要将工具提示替换为 JWindow/JEditorPane,您需要自己将其“连接在一起”。这是an example,它使用JWindow(显示BufferedImage 实例)。
【讨论】:
Icon normalIcon = new ImageIcon("normal-icon.png"); // Icon for normal situations
JButton button = new JButton(); // initialize the button
button.setIcon(normalIcon); // set the normal situation icon
Icon rollOverIcon = new ImageIcon("roll-over.png"); // Icon for roll over (hovering effect)
button.setRolloverIcon(rollOverIcon); // Set the icon attaching with the roll-over event
【讨论】:
您可以使用setRolloverIcon。这是example。
【讨论】: