为何设置JFrame背景失败

younglee2013 2014-09-17 08:47:43
代码如下:
import java.awt.*;
import javax.swing.*;
public class mFramewithPictureAsBack {
public mFramewithPictureAsBack() {}
public static void main(String[] args) {
JFrame frame = new JFrame("背景图设置");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("images//a4.png");
JLabel label = new JLabel(img);
label.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
Container con = frame.getContentPane();
con.setLayout(new GridLayout(1, 1));
JButton btn = new JButton("按钮");
con.add(btn);
((JPanel)con).setOpaque(false);
frame.setSize(500, 300);
frame.setVisible(true);
}
}
...全文
186 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
thisisnew 2014-09-19
  • 打赏
  • 举报
回复
ImageIcon img = new ImageIcon("images//a4.png"); 估计应该是这里的路径出现问题,你debug下,看看图片有没有加载进来

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧