Using an image for the background of a JPanel and JButton

早过忘川 提交于 2019-12-20 06:39:59

问题


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...


回答1:


For the JButton, use this:

JButton button = new JButton("Button Name", new ImageIcon("foo.png");

The Panel is a bit more interesting. This is a good method, though:

ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage());


来源:https://stackoverflow.com/questions/8373006/using-an-image-for-the-background-of-a-jpanel-and-jbutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!