【问题标题】:How to get mouseover/pop-up effect on button?如何在按钮上获得鼠标悬停/弹出效果?
【发布时间】:2012-04-27 12:01:38
【问题描述】:

如何在JButton 上获得鼠标悬停效果,这应该类似于我们将在 Stackoveflow 中的标签 鼠标悬停上获得的效果?例如

【问题讨论】:

标签: java swing mouseover jbutton


【解决方案1】:

JComponent.setToolTipText(String)。工具提示在一定程度上支持 HTML,但不支持在 SO 标记弹出窗口底部提供链接的功能。

为此,您需要将工具提示替换为 JWindow/JEditorPane,您需要自己将其“连接在一起”。这是an example,它使用JWindow(显示BufferedImage 实例)。

【讨论】:

    【解决方案2】:
    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
    

    【讨论】:

      【解决方案3】:

      您可以使用setRolloverIcon。这是example

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-20
        • 2013-01-17
        • 2017-06-11
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 2016-04-26
        相关资源
        最近更新 更多