java 表格不能编辑_新人求解,为什么表格无法编辑

已结贴√

问题点数:20 回复次数:9

ca56232b3bbedf9a539d07f37fffb99a.gif

3144d8b7615c79d9f638db40d5689d26.gif

a218af6549b45ee526caf607ebff1358.gif

0f8df0e29816ae721419de940fb833d1.gif

新人求解,为什么表格无法编辑

import java.awt.*;

import javax.swing.*;

import javax.swing.table.AbstractTableModel;

import javax.swing.table.DefaultTableModel;

public class tb extends AbstractTableModel{//表格定义

String[] head={"会员","xm","check","year","ye","color"};

Class[] typeArray={Object.class,Object.class,Boolean.class,Object.class,Double.class,Color.class};

Object[] data1={"1001","dd",false,23,1577,Color.ORANGE};

Object[] data2={"1001","dd",false,24,1577,Color.ORANGE};

Object[] data3={"1001","dd",false,25,1577,Color.ORANGE};

Object[] data4={"1001","dd",false,26,1577,Color.ORANGE};

Object[][]data={data1,data2,data3,data4};

public int getColumnCount(){

return head.length;

}

public int getRowCount(){

return data.length;

}

public String getColumnName(int col){

return head[col];

}

public Object getValueAt(int r,int c){

return data[r][c];

}

public Class getColumnClass(int c){

return typeArray[c];

}

public Boolean isCellEdittable(int r,int c){

return true;

}

public void setValueAt(Object value,int r,int c){

data[r][c]=value;

this.fireTableCellUpdated(r,c);

}

}

import javax.swing.*;

import javax.swing.table.*;

import javax.swing.event.*;

public class tb1 extends JFrame {//主调程序

tb tby=new tb();

JTable table =new JTable(tby);

TableListener tablelistener=new TableListener();

tb1(){

table.getSelectionModel().addListSelectionListener(tablelistener);

table.getColumnModel().addColumnModelListener(tablelistener);

table.getModel().addTableModelListener(tablelistener);

this.add(table);

this.setBounds(200,200,700,300);

this.setVisible(true);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args){

new tb1();

}

}

class TableListener implements ListSelectionListener,TableColumnModelListener,TableModelListener{

int row=0;

int col=0;

JTable table;

@Override

public void tableChanged(TableModelEvent e) {

String str=(String) table.getValueAt(row,col);

System.out.println(str);

}

@Override

public void columnAdded(TableColumnModelEvent e) {

// TODO Auto-generated method stub

}

@Override

public void columnRemoved(TableColumnModelEvent e) {

// TODO Auto-generated method stub

}

@Override

public void columnMoved(TableColumnModelEvent e) {

// TODO Auto-generated method stub

}

@Override

public void columnMarginChanged(ChangeEvent e) {

// TODO Auto-generated method stub

}

@Override

public void columnSelectionChanged(ListSelectionEvent e) {

col= table.getSelectedColumn();

}

@Override

public void valueChanged(ListSelectionEvent e) {

row=table.getSelectedRow();

}

}

所有源码都已贴出,是什么地方出错,望各位帮忙,谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值