akf*_*akf 10
看看JLayeredPanes. 这是一个教程.
编辑:
如果panelA是AWT组件,则很难让panelB重叠.来自Sun的文章" 混合重型和轻型部件:
不要在容器内混合轻量级(Swing)和重量级(AWT)组件,轻量级组件应与重量级组件重叠.
但是,如果您希望panelA完全填充Frame,为什么不将panelB添加为panelA的组件?
EDIT2:
如果你可以使panelB成为一个重量级组件,那么你可以使用JLayeredPane.
这是一个快速模型,显示如何:
public static void main(String[] args){
new GUITest();
}
public GUITest() {
frame = new JFrame("test");
frame.setSize(300,300);
addStuffToFrame();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
frame.setVisible(true);
}
});
}
private void addStuffToFrame() {
Panel awtPanel = new Panel();
awtPanel.setBackground(Color.blue);
//here you can fool around with the pane:
//first, you can see how the layered pane works by switching the
//DEFUALT_LAYER and PALLETTE_LAYER back and forth between the two panels
//and re-compiling to see the results
awtPanel.setSize(200,300);
frame.getLayeredPane().add(awtPanel, JLayeredPane.DEFAULT_LAYER);
//next you comment out the above two lines and
//uncomment the following line. this will give you the desired effect of
//awtPanel filling in the entire frame, even on a resize.
//frame.add(awtPanel);
Panel awtPanel2 = new Panel();
awtPanel2.setBackground(Color.red);
awtPanel2.setSize(300,200);
frame.getLayeredPane().add(awtPanel2,JLayeredPane.PALETTE_LAYER);
}
Run Code Online (Sandbox Code Playgroud)