有两个panel 下面的panel加张图片做为背景,上面的panel加控件.例如按钮,最终效果是加控件的panel为透明,可以看见背景!按钮也可见!!可惜研究半天没达到这样的效果。请看红色代码部分,我加了这行代码后,发现背景就看不见了,如果,去掉它,背景就能看得见。请大家帮我看看,谢谢
第一个图只看得见按钮,第二个图片只看到背景package com.swing.japplet;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
Container cc = frame.getContentPane();
cc.setLayout(new BorderLayout());
Icon icon = new ImageIcon("F:/workspace/Test/src/pic/1x.jpg"); // 添加图片
JLabel label = new JLabel(icon);
frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
label.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight());
JButton b1 = new JButton("点击一下");

//b1.setBounds(150, 150, 50, 50);
b1.setSize(new Dimension(200,200));
cc.add(b1);

((JPanel) cc).setOpaque(false);

frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}