java - 如何将 Icon 设置为 JButton 而不会在按下时丢失动画?

标签 java swing animation icons jbutton

我使用在线工具创建了自定义按钮图标,然后下载了 .png 文件。 我已经在 J​​Button(Swing 应用程序)中设置了图标,但是,当按下按钮时,它不会在单击按钮时显示常规动画。 是否可以在不失去这种效果的情况下设置图标? 谢谢(这是代码)

public final JButton SEARCH = new JButton();
SEARCH.setBorder(null);
SEARCH.setContentAreaFilled(false);

ImageIcon searchb = new ImageIcon(getClass().getClassLoader().getResource("search.png"));
SEARCH.setIcon(searchb);

最佳答案

您必须根据您的要求使用不同的图标(图像)。 这意味着您必须使用另一个图像,该图像类似于使用原始图像按下的按钮

见下文

JButton b = new JButton();
b.setPressedIcon(); // shows when button is pressed 
b.setSelectedIcon(); // shows when button is selected(applicable for toggle buttons) 
b.setDisabledIcon(); // shows when button is disabled 
b.setRolloverIcon(); // shows when mouse pointer hovering on the button

enter image description here

关于java - 如何将 Icon 设置为 JButton 而不会在按下时丢失动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65492282/

相关文章:

javascript - d3 中的条件转换

java - RMI服务运行方式与socket类似

java - JAVA中汉字生僻字从UTF8到BIG5的映射

java - 在 Java 上的 JForm 中滑动 JPanel 内容

java - JMenuBar 重新绘制我的 JPanel

java - JFrame 最小化后不会重新最大化

android - 如何动画缩放相对布局(其中包含许多布局和 ImageViews 里面)

java - GXT : Cancel click event on grid header

java - 在 Android webview 中显示 Unicode 字符

python - Kivy:用 Canvas 制作动画图像的正确方法是什么?