为JFrame添加背景图片的方法
//得到主窗口的内容面板
Container cp = this.getContentPane();
//设置主面板的布局为空,否则为流布局,加入部件后无法显示图片
cp.setLayout(null);
//设为透明的才能显示出图片
((JPanel)cp).setOpaque(false);
//将带有图片的标签加入到最底层
this.getLayeredPane().add(label_bg, new Integer(Integer.MIN_VALUE));
//设置图片的位置和大小
label_bg.setBounds(0, 0,screen_width,screen_height);

浙公网安备 33010602011771号