| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1602 人关注过本帖
标题:关于jtable添加行的问题
只看楼主 加入收藏
l0w5l0
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-10-7
结帖率:100%
收藏
 问题点数:0 回复次数:2 
关于jtable添加行的问题
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.*;

public class testq  extends JFrame
{
    int row;
    int column;
    Object[][] cells=    {{"001","zhang","88"},
            {"002","wang","90"},
            {"003","lin","99"},
            {"004","liao","60"},
            {"  "," "," "}
            };
    String[]    columnsName={"NO","Name","Score"};
    testq()
    {
        row=5;
        column=3;
        JTable table=new JTable(cells,columnsName);
        add(new JScrollPane(table),BorderLayout.CENTER);
        table.setModel(new TableModel());
    }
    
        public static void main(String[]args)
    {
        testq table=new testq();
        table.setVisible(true);
        table.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        table.setSize(500,500);
        
    }
    
    class TableModel extends DefaultTableModel
    {
        public TableModel()
        {
            addTableModelListener(new TableModelListener()
            {
                public void tableChanged(TableModelEvent e)
                {
                    if((String)getValueAt(e.getFirstRow(),e.getColumn())!=" ")
                    {
                        System.out.println(getRowCount());
                        Object[] object=new Object[]{" "," "," " };
                        addRow(object);
                    }
                }
            } );
        }
        public int getRowCount()
        {
            return row;
        }
        public int getColumnCount()
        {
            return column;
        }
        public Object getValueAt(int row ,int column)
        {
            return cells[row][column];
        }
        public String getColumnName(int c)
        {
            return columnsName[c];
        }
        public boolean isCellEditable(int row,int column)
        {
            return true;
        }    
    }
}



为什么每次运行时都会出现越界的异常???
搜索更多相关主题的帖子: jtable 
2008-11-01 10:26
hacker507
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2008-10-6
收藏
得分:0 
太花呢,看的不怎么懂,写电注释啊
2008-11-01 15:29
qwe885167759
Rank: 4
等 级:业余侠客
威 望:5
帖 子:148
专家分:259
注 册:2013-3-12
收藏
得分:0 
数组申请的空间小了,你给数组的行和列的数值都+1就行了

我本楚狂人,凤歌笑孔丘
2014-05-23 23:50
快速回复:关于jtable添加行的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027967 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved