class StuInfo extends JDialog{
JPanel pStuInfo = new JPanel(); JPanel pStuEdit = new JPanel();
JLabel lbSno = new JLabel();
JLabel lbName = new JLabel();
JLabel lbSex = new JLabel();
JLabel lbDept = new JLabel();
JLabel lbDoom = new JLabel();
JLabel lbCheckin = new JLabel(); JTextField tfSno = new JTextField();
JTextField tfName = new JTextField();
JTextField tfSex = new JTextField();
JTextField tfDept = new JTextField();
JTextField tfDoom = new JTextField();
JTextField tfCheckin = new JTextField(); JPanel pShow = new JPanel();
JScrollPane spShow = new JScrollPane();
JTable table = new JTable();
JTableHeader tableheader = table.getTableHeader();
Vector vColnames = new Vector();
Vector vColumn1 = new Vector();
Vector vColumn2 = new Vector(); static int lbX = 10;
static int lbY1 = 10;
static int lbLength = 60;
static int lbWidth = 40;
static int lbBetween = 20;
static int tfX = 80;
static int tfY1 = 10;
static int tfLength = 100;
static int tfWidth = 40;
static int tfBetween = 20; public StuInfo(JFrame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jsInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
} public StuInfo(){
this(new JFrame(), "学生信息", false);
this.setLocation(600, 100);
this.setSize(740, 500);
} private void jsInit() throws Exception{
pStuInfo.setLayout(null);
pStuInfo.setBackground(Color.pink); pStuEdit.setLayout(null);
spShow.setLayout(null); pStuEdit.setBounds(10, 10, 200, 380);
spShow.setBounds(220, 10, 500, 380); spShow.setBackground(Color.MAGENTA); lbSno.setBounds(lbX, lbY1, lbLength, lbWidth);
lbName.setBounds(lbX, lbY1+lbWidth+lbBetween, lbLength, lbWidth);
lbSex.setBounds(lbX, lbY1+lbWidth*2+lbBetween*2, lbLength, lbWidth);
lbDept.setBounds(lbX, lbY1+lbWidth*3+lbBetween*3, lbLength, lbWidth);
lbDoom.setBounds(lbX, lbY1+lbWidth*4+lbBetween*4, lbLength, lbWidth);
lbCheckin.setBounds(lbX, lbY1+lbWidth*5+lbBetween*5, lbLength, lbWidth); tfSno.setBounds(tfX, tfY1, tfLength, tfWidth);
tfName.setBounds(tfX, tfY1+tfWidth+tfBetween, tfLength, tfWidth);
tfSex.setBounds(tfX, tfY1+tfWidth*2+tfBetween*2, tfLength, tfWidth);
tfDept.setBounds(tfX, tfY1+tfWidth*3+tfBetween*3, tfLength, tfWidth);
tfDoom.setBounds(tfX, tfY1+tfWidth*4+tfBetween*4, tfLength, tfWidth);
tfCheckin.setBounds(tfX, tfY1+tfWidth*5+tfBetween*5, tfLength, tfWidth); pStuEdit.add(lbSno);
pStuEdit.add(lbName);
pStuEdit.add(lbSex);
pStuEdit.add(lbDept);
pStuEdit.add(lbDoom);
pStuEdit.add(lbCheckin);
pStuEdit.add(tfSno);
pStuEdit.add(tfName);
pStuEdit.add(tfSex);
pStuEdit.add(tfDept);
pStuEdit.add(tfDoom);
pStuEdit.add(tfCheckin); vColnames.add("学号");
vColnames.add("姓名");
vColnames.add("性别");
vColnames.add("专业");
vColnames.add("宿舍");
vColnames.add("入住时间"); vColumn1.add("2009402035");
vColumn1.add("LilyKingdom");
vColumn1.add("女");
vColumn1.add("汉语言文学");
vColumn1.add("G123");
vColumn1.add("2020-9-6");
vColumn2.add(vColumn1); table = new JTable(vColumn2, vColnames); table.setPreferredSize(new Dimension(400,300));
spShow.getViewport().add(table);
this.getContentPane().add(pStuInfo, BorderLayout.CENTER);
pStuInfo.add(pStuEdit);
pStuInfo.add(spShow);
this.setVisible(true);
}
public static void main(String[] args){
new StuInfo();
}
}
JPanel pStuInfo = new JPanel(); JPanel pStuEdit = new JPanel();
JLabel lbSno = new JLabel();
JLabel lbName = new JLabel();
JLabel lbSex = new JLabel();
JLabel lbDept = new JLabel();
JLabel lbDoom = new JLabel();
JLabel lbCheckin = new JLabel(); JTextField tfSno = new JTextField();
JTextField tfName = new JTextField();
JTextField tfSex = new JTextField();
JTextField tfDept = new JTextField();
JTextField tfDoom = new JTextField();
JTextField tfCheckin = new JTextField(); JPanel pShow = new JPanel();
JScrollPane spShow = new JScrollPane();
JTable table = new JTable();
JTableHeader tableheader = table.getTableHeader();
Vector vColnames = new Vector();
Vector vColumn1 = new Vector();
Vector vColumn2 = new Vector(); static int lbX = 10;
static int lbY1 = 10;
static int lbLength = 60;
static int lbWidth = 40;
static int lbBetween = 20;
static int tfX = 80;
static int tfY1 = 10;
static int tfLength = 100;
static int tfWidth = 40;
static int tfBetween = 20; public StuInfo(JFrame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jsInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
} public StuInfo(){
this(new JFrame(), "学生信息", false);
this.setLocation(600, 100);
this.setSize(740, 500);
} private void jsInit() throws Exception{
pStuInfo.setLayout(null);
pStuInfo.setBackground(Color.pink); pStuEdit.setLayout(null);
spShow.setLayout(null); pStuEdit.setBounds(10, 10, 200, 380);
spShow.setBounds(220, 10, 500, 380); spShow.setBackground(Color.MAGENTA); lbSno.setBounds(lbX, lbY1, lbLength, lbWidth);
lbName.setBounds(lbX, lbY1+lbWidth+lbBetween, lbLength, lbWidth);
lbSex.setBounds(lbX, lbY1+lbWidth*2+lbBetween*2, lbLength, lbWidth);
lbDept.setBounds(lbX, lbY1+lbWidth*3+lbBetween*3, lbLength, lbWidth);
lbDoom.setBounds(lbX, lbY1+lbWidth*4+lbBetween*4, lbLength, lbWidth);
lbCheckin.setBounds(lbX, lbY1+lbWidth*5+lbBetween*5, lbLength, lbWidth); tfSno.setBounds(tfX, tfY1, tfLength, tfWidth);
tfName.setBounds(tfX, tfY1+tfWidth+tfBetween, tfLength, tfWidth);
tfSex.setBounds(tfX, tfY1+tfWidth*2+tfBetween*2, tfLength, tfWidth);
tfDept.setBounds(tfX, tfY1+tfWidth*3+tfBetween*3, tfLength, tfWidth);
tfDoom.setBounds(tfX, tfY1+tfWidth*4+tfBetween*4, tfLength, tfWidth);
tfCheckin.setBounds(tfX, tfY1+tfWidth*5+tfBetween*5, tfLength, tfWidth); pStuEdit.add(lbSno);
pStuEdit.add(lbName);
pStuEdit.add(lbSex);
pStuEdit.add(lbDept);
pStuEdit.add(lbDoom);
pStuEdit.add(lbCheckin);
pStuEdit.add(tfSno);
pStuEdit.add(tfName);
pStuEdit.add(tfSex);
pStuEdit.add(tfDept);
pStuEdit.add(tfDoom);
pStuEdit.add(tfCheckin); vColnames.add("学号");
vColnames.add("姓名");
vColnames.add("性别");
vColnames.add("专业");
vColnames.add("宿舍");
vColnames.add("入住时间"); vColumn1.add("2009402035");
vColumn1.add("LilyKingdom");
vColumn1.add("女");
vColumn1.add("汉语言文学");
vColumn1.add("G123");
vColumn1.add("2020-9-6");
vColumn2.add(vColumn1); table = new JTable(vColumn2, vColnames); table.setPreferredSize(new Dimension(400,300));
spShow.getViewport().add(table);
this.getContentPane().add(pStuInfo, BorderLayout.CENTER);
pStuInfo.add(pStuEdit);
pStuInfo.add(spShow);
this.setVisible(true);
}
public static void main(String[] args){
new StuInfo();
}
}
=>
spShow.getViewport().setView(table);
pStuInfo.setLayout(null);
把这句去掉即可