gpt4 book ai didi

Java 按钮 mouseclicked joptionpane

转载 作者:行者123 更新时间:2023-12-02 04:42:39 26 4
gpt4 key购买 nike

我正在扩展 JButton 类并使用 ImageIcon 作为按钮背景。我还添加了一个 mouseListener,以便当鼠标悬停在按钮上或按下按钮时可以更改按钮的图像。这一切都工作正常,但问题是,当单击按钮时,会显示 JOptionPane,询问用户“您确定吗”,而显示选项 Pane 时,不会执行按钮 MouseClicked、mouseExited 或 mouseReleased 方法,因此按钮看起来像是一直按住直到使用选项对话框。删除对话框不是一个选项。有没有办法让鼠标事件在对话框显示之前或期间执行?

最佳答案

I have also added a mouseListener so I can change the image of the button when the mouse hovers over the button or presses the button.

阅读AbstractButton API。有一些方法允许您为这些情况指定图标。例如setPressedIcon()

it looks like the button is stuck pressed until the use deals with the option dialog.

不确定在显示选项 Pane 之前 ButtonModel 状态是否已更改。无论如何,你可以尝试使用:

 button.paintImmediately(...);

在显示选项 Pane 之前。如果 ButtonModel 状态已更新,则应在正常状态下重新绘制按钮。请注意,这种方法应该很少使用,因为它会影响绘画性能。

关于Java 按钮 mouseclicked joptionpane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30009655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com