请高手解析一下下面的程序为什么不能得到想要的结果...

来源:百度知道 编辑:UC知道 时间:2024/07/04 20:57:05
package system.paraPanel;

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

public class Test extends JPanel {

private JLabel pathLab;
private JTextField pathField;
private JButton chooserB;

private JPanel p1,p2,panel;
public Test(){
super();
setSize(300,230);
setLayout(null);
setBorder(new TitledBorder("数据路径设置"));

p1 = initPanel("数据库文件路径");
p2 = initPanel("本软件安装路径");

p1.setBounds(5,20,280,90);
p2.setBounds(5,110,280,90);
}

public JPanel initPanel(String str){
panel = new JPanel();
panel.setBorder(new EtchedBorder(EtchedBorder.RAISED));

panel.add(p

改一下构造方法
public Test() {
super();
setSize(300, 230);
setLayout(null);
setBorder(new TitledBorder("数据路径设置"));

p1 = initPanel("数据库文件路径");
p2 = initPanel("本软件安装路径");

p1.setBounds(5, 20, 280, 90);
p2.setBounds(5, 110, 280, 90);

this.add(p1);//把这两个panel加到外层的panel里
this.add(p2);
this.setVisible(true);
}