我是个java的出学者,我正在做个成绩查询系统,比如按学号查询,我现在想把查询到的学生信息以(JTable)表格的形式输出,请各位大侠指点!非常感谢!!!

解决方案 »

  1.   


        JTable table = null;
        DefaultTableModel defaultModel = null;    String[] name = {"字段 1","字段 2","字段 3","字段 4","字段 5"};
            String[][] data = new String[5][5];
            int value =1;
            for(int i=0; i<data.length; i++)
            {
                for(int j=0; j<data[i].length ; j++)
                    data[i][j] = String.valueOf(value++);
            }
                      
            defaultModel = new DefaultTableModel(data,name);
            table=new JTable(defaultModel);
      

  2.   

    这是静态的吧!
    我想要实现的功能是,如:按学号查询,当我在JTextField 中输入某某的学号时,点查询,就能把成绩信息显示到表中!请您在指教!
      

  3.   

    用一个Vector来构造JTable,动态更改Vector的元素,再调用JTable的updateUI方法就可以更新JTable了
      

  4.   

    楼上的gg or jj Vector怎么用啊,能不能给各例子啊?
      

  5.   

    class MyTable extends JTable{
    private JTable table=null;
    private Vector vectorRow=null;
    private Vector vectorColumn=null;
    MyTable(){
    super(getRow(),getColumn());
    } Vector getRow()
    {
    if(vectorRow==null)
    {
    vectorRow=new Vector();
    }
    return vectorRow;
    } Vector getColumn()
    {
    if(vectorColumn==null)
    {
    vectorColumn=new Vector();
    vectorColumn.add(new String("连接ID"));
    vectorColumn.add(new String("用户名"));
    vectorColumn.add(new String("地址"));
    vectorColumn.add(new String("端口"));
    }
    return vectorColumn;
    } void addRow(String strConnectionId,String strUserName,String strIP,String strPort)
    {
    Vector vectorData=new Vector();
    vectorData.add(strConnectionId);
    vectorData.add(strUserName);
    vectorData.add(strIP);
    vectorData.add(strPort);
    vectorRow.add(vData);
    this.updateUI();
    } void removeRow(String strConnectionId,String strUserName,String strIP,String strPort)
    {
    Vector vectorData=new Vector();
    vectorData.add(strConnectionId);
    vectorData.add(strUserName);
    vectorData.add(strIP);
    vectorData.add(strPort);
    vectorRow.remove(vData);
    this.updateUI();
    }
    void clear()
    {
    vectorRow.clear();
    this.updateUI();
    }
    }为神六喝彩,向所有科技工作者致敬!
    拒绝日货。
    为CSDN 小助手的作者致敬!
      

  6.   

    private JTable table=null;应该去掉这一句为神六喝彩,向所有科技工作者致敬!
    拒绝日货。
    为CSDN 小助手的作者致敬!
      

  7.   

    vectorRow.add(vData);
    vectorRow.remove(vData);
    应该改成:
    vectorRow.add(vectorData);
    vectorRow.remove(vectorData);为神六喝彩,向所有科技工作者致敬!
    拒绝日货。
    为CSDN 小助手的作者致敬!
      

  8.   

    http://www.matrix.org.cn/resource/article/481.html
    我是看了这篇文章后自己实现的,你也可以参考下.我也是初学者,相信看过之后你能实现你需要的功能