table = new JTable();

table.setModel(new DefaultTableModel(
obj,
new String[] {
"", "\u7528\u6237\u540D", "\u7528\u6237ID", "\u5BC6\u7801", "\u5DE5\u53F7", "\u72B6\u6001"
}
) {
Class[] columnTypes = new Class[] {
Boolean.class, Object.class, Object.class, Object.class, Object.class, Object.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
});
   
table.setBounds(37, 64, 373, 151);
table.setPreferredSize(new Dimension(300,200));

JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setViewportView(table);

scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
scrollPane.setBounds(0, 39, 442, 113);
contentPane.add(scrollPane);

JButton button = new JButton("删除");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

for(int i=0;i<obj.length;i++){
if(table.getValueAt(i, 0)==Boolean.TRUE){

SysUserDaoImpl sysUserDaoImpl=new SysUserDaoImpl();
sysUserDaoImpl.deletUser(obj[i][2]);

}
}

//刷新JFrame
Yhlb.this.setVisible(false);
Yhlb y = new Yhlb();
y.setVisible(true);

}
});
button.setBounds(338, 10, 93, 23);
contentPane.add(button);

JLabel lblNewLabel = new JLabel("用户列表");
lblNewLabel.setBounds(10, 10, 81, 23);
contentPane.add(lblNewLabel);
}
其中的部分代码,其中的obj是从数据库总调出数据显示出来,那里具体就不放出来了,有关JTable和JScrollPane的内容我就贴出来了
怎么就不行呢,出现什么问题了,

解决方案 »

  1.   

    你看我写的也出问题了,你能帮帮我吗?package com.test1;
    import java.awt.*;
    import java.util.Vector;import javax.swing.*;
    public class 查询界面 extends JFrame{ //北部区域
    JLabel jl1,jl2;
    JPanel jp1;
    JTextField jtf;
    JButton jb1;

    //南部区域
    JButton jb2,jb3;
    JPanel jp2;
    JLabel jl3;

    //中部区域
    JTabbedPane jtp;//选项卡新窗口
    JTable jt1,jt2;//桌面控件
    JPanel jp3=null,jp4=null;
    JScrollPane jsp1=null,jsp2=null;
     Vector rowData1,columnNames1,rowData2,columnNames2;
     
    public 查询界面(){

    //创建组件
    jl1=new JLabel(new ImageIcon("image\\up.PNG"));
    jl2=new JLabel("请输入查询专业:");
    jb1=new JButton("查询");

    jb2=new JButton("详细信息");
    jb3=new JButton("修改/删除");
    jl3=new JLabel(new ImageIcon("image\\down.PNG"));

    jp3=new JPanel();
    jp3.setBackground(Color.gray);//设置面板背景色
    jp4=new JPanel();
    jp4.setBackground(new Color(0,0,255));

    //将面板添加在选项窗格上
    //名称,参数
    jtp.add("大学生查询", jp3);
    jtp.add("企业查询", jp4);
    jp3.add(jsp1);
    jp4.add(jsp2);

    //设置列名
    columnNames1=new Vector();
    columnNames1.add("企业编号");
    columnNames1.add("企业名称");
    columnNames1.add("企业等级");
    columnNames1.add("地址");

    columnNames2=new Vector();
    columnNames2.add("大学生学号");
    columnNames2.add("姓名");
    columnNames2.add("年龄");
    columnNames2.add("性别");
    columnNames2.add("毕业院校");

    //可以放置多行
    rowData2=new Vector();
    Vector hang1=new Vector();
     hang1.add("0001");
     hang1.add("联想");
     hang1.add("一级");
     hang1.add("北京");
     rowData1.add(hang1);
     
     rowData2=new Vector();
    Vector hang2=new Vector();
    hang2.add("100810622");
    hang2.add("罗毅");
    hang2.add("21");
    hang2.add("男");
    hang2.add("山东交通学院");
    rowData2.add(hang2);
     
     //初始化JTable
     jt1=new JTable(rowData1,columnNames1);
     jt2=new JTable(rowData2,columnNames2);
     
     //初始化JScrollPane
     jsp1=new JScrollPane(jt1);
     jsp2=new JScrollPane(jt2);
     
     jp1.add(jl2);
     jp1.add(jb1);
     
     jp2.add(jb2);
     jp2.add(jb3);

     jp3.add(jsp1);
     jp3.add(jsp2);
     
     //加到JFrame
     this.add(jl1,BorderLayout.SOUTH);
     this.add(jp1);
     this.add(jtp);
     this.add(jp2);
     this.add(jl3,BorderLayout.NORTH);
     
     this.setTitle("查询界面");
     this.setSize(300, 300);
     this.setLocation(500, 200);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setVisible(true);
     
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    查询界面 test=new 查询界面();
    }}结果如下:
    Exception in thread "main" java.lang.NullPointerException
    at com.test1.查询界面.<init>(查询界面.java:44)
    at com.test1.查询界面.main(查询界面.java:114)