Java的:使用图像作为按钮 [英] Java: using an image as a button

查看:206
本文介绍了Java的:使用图像作为按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个形象在Java中的一个按钮,我试图做到这一点:

I would like to use an image as a button in Java, and I tried to do this:

BufferedImage buttonIcon = ImageIO.read(new File("buttonIconPath"));
button = new JButton(new ImageIcon(buttonIcon));

但是,这仍然显示了图像背后的实际按钮,我只想图像充当按钮,我该怎么做呢?

But this still shows the actual button behind the image, I would only like the image to function as the button, how can I do this?

先谢谢了。

编辑:溶液中发现的

JZ​​D答案,别的东西我发现的组合解决了这个问题:

A combination of jzd answer and something else I found solved the problem:

button.setBorder(BorderFactory.createEmptyBorder());
button.setContentAreaFilled(false);

这做的伎俩对我来说,谢谢您的回答!

This did the trick for me, thanks for your answers!

推荐答案

删除边框,像这样:

button.setBorder(BorderFactory.createEmptyBorder());

这篇关于Java的:使用图像作为按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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