請問怎么樣獲得JTable中當前的行列數
我為它加上了KeyListener的監聽
需要對其中的數據進行指定的更改
請指教

解决方案 »

  1.   

    public TableModel getModel();//获得model
    model.getColumnCount();//列数
    model.getRowCount() ; //行数
      

  2.   

    这是我的一个TABLE初始化的函数
    private void initTable(JTable table) {
            if (ALLOW_ROW_SELECTION) { // true by default
                ListSelectionModel rowSM = table.getSelectionModel();
                rowSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        if (e.getValueIsAdjusting()) return;
                            ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                        if (lsm.isSelectionEmpty()) {
                            ;
                        }
                        else {
                            int sRow = lsm.getMinSelectionIndex();//取得选中的行
                                               }
                    }
                });
            }
            else {
                table.setRowSelectionAllowed(false);
            }
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        }