使用图像作为JPanel和JButton的背景 [英] Using an image for the background of a JPanel and JButton
本文介绍了使用图像作为JPanel和JButton的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用我在photoshop中制作的图像作为GUI的背景。我怎么做?我也想在动作执行后在按钮背景中显示一些图像......
I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed...
推荐答案
对于JButton,使用这个:
For the JButton, use this:
JButton button = new JButton("Button Name", new ImageIcon("foo.png");
Panel更有趣。这是一个很好的方法,但是:
The Panel is a bit more interesting. This is a good method, though:
ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage());
这篇关于使用图像作为JPanel和JButton的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文