import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.LayerUI;
public class MyJLayer extends JFrame {
public static void main(String[] args) {
MyJLayer jlayer = new MyJLayer();
jlayer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JButton button = new JButton("Debug Only.");
panel.add(button);
UI ui = new UI();
JLayer<JPanel> jLayer = new JLayer<JPanel>(panel, ui);
jlayer.add(jLayer);
jlayer.setSize(100, 100);
jlayer.setVisible(true);
}
}
class UI extends LayerUI<JPanel>{
public void paint(Graphics g, JPanel c){
super.paint(g, c);
Graphics2D g2d = (Graphics2D)g.create();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .8f));
g2d.setColor(Color.BLUE);
g2d.fillRect(0, 0, c.getWidth(), c.getHeight());
g2d.dispose();
}
}
面板根本不显示蓝色,但我不知道为什么。谁能帮帮我?我就是查不出来。 http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html