importjava.awt.*;importjavax.swing.*;publicclassJLextendsJFrame{Integer[]layer={JLayeredPane.DEFAULT_LAYER,JLayeredPane.PALETTE_LAYER,JLayeredPane.MODAL_LAYER,JLayeredPan...
import java.awt.*;
import javax.swing.*;
public class JL extends JFrame
{
Integer[] layer={JLayeredPane.DEFAULT_LAYER,JLayeredPane.PALETTE_LAYER,JLayeredPane.MODAL_LAYER,JLayeredPane.POPUP_LAYER,JLayeredPane.DRAG_LAYER};
Color[] color={Color.red,Color.yellow,Color.cyan,Color.green,Color.blue};
Point position=new Point(30,30);
JLabel[] la=new JLabel[5];
JL()
{
super("JL");
JLayeredPane layeredp=getLayeredPane();
for(int i=0;i<5;i++)
{
la[i]=create("第"+(i+1)+"层",color[i],position);
position.x=position.x+(i*25);
position.y=position.y+(i*25);
layeredp.add(la[i],layer[i]);
}
setSize(300,300);
setVisible(true);
}
public JLabel create(String content,Color color,Point position)
{
JLabel label=new JLabel(content);
label.setVerticalAlignment(JLabel.TOP);
label.setBackground(color);
label.setForeground(Color.black);
label.setBounds(position.x,position.y,120,120);
return label;
}
public static void main(String[] args)
{
new JL();
}
}
为什么没出现有成次的背景色,全是白色,只有标签明啊?
谢谢各位大侠指点下
展开