今天在csdn上看到别人问这个问题.就写了个类.
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
public class test {
JTable table=new JTable();
DefaultTableModel model;
public test(){
JFrame frame=new JFrame();
this.gettable();
//table.addMouseListener(this);
JScrollPane src=new JScrollPane(table);
frame.setSize(new Dimension(400,200));
src.setBounds(0, 0, 400, 200);
frame.add(src);
frame.setVisible(true);
}
public void gettable(){
Object ss[][]={
{"12","12"},
{"13","13"}
};
Vector v1=new Vector();
Vector v2=new Vector();
for(int i=1;i<3;i++){
Vector v=new Vector();
v.addElement(i*10);
v.addElement((i+1)*10);
v1.addElement(v);
}
v2.addElement("A");
v2.addElement("B");
//model=;
DefaultTableModel model=new DefaultTableModel(v1,v2);
table.setModel(new DefaultTableModel(v1,v2) {
public boolean isCellEditable(int row,int col){
if(row==1) return false;
return true;
}
});
}
public static void main(String args[]){
new test();
}
}
呵呵有问题大家一起探讨阿。我是新手