一个布局管理器问题
开发老张 2010-01-06 04:09:06 一个简单的程序:
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{
private Container con;
private JPanel jp1,jp2;
Test(){
con = this.getContentPane();
con.setLayout(new BorderLayout());
jp1 = new JPanel();
jp2 = new JPanel();
jp2.setBackground(Color.red);
con.add(jp1,BorderLayout.CENTER);
con.add(jp2,BorderLayout.SOUTH);
this.setVisible(true);
this.setBounds(100, 100, 600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Test();
}
}
此时显示正常,但我将jp1或者jp2增加一个其内部的管理器,怎么就显示不出BorderLayout.SOUTH的Panel了呢?
如下程序:
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{
private Container con;
private JPanel jp1,jp2;
Test(){
con = this.getContentPane();
con.setLayout(new BorderLayout());
jp1 = new JPanel();
jp2 = new JPanel(new BorderLayout());
jp2.setBackground(Color.red);
con.add(jp1,BorderLayout.CENTER);
con.add(jp2,BorderLayout.SOUTH);
this.setVisible(true);
this.setBounds(100, 100, 600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new Test();
}
}