如何删除JButton上的图标? [英] How to Remove an icon on a JButton?

查看:128
本文介绍了如何删除JButton上的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个记忆匹配游戏,并且我点击了JButton时放置的图标图像。我的问题是,有没有办法从JButton中删除图标?我希望当用户点击时显示图像,并且如果用户点击的第二个按钮与第一个按钮没有相同的图像,那么它就会消失......任何想法?

I'm trying to make a memory matching game, and I have icon images that I place onto a JButton when it is clicked. My question is, is there a way to remove the Icon from the JButton? I want to make so when a user clicks, the image is displayed, and if the second button the user clicks does not have the same image as the first button, then it disappears...any ideas?

推荐答案

简单,将图标设置为 null 。它没有图标,因此将其删除。

Simple, Set the icon to null. It doesn't have an icon, so it removes it.

button.setIcon(null);

这篇关于如何删除JButton上的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆