import javax.swing.table.*;public class testtm extends AbstractTableModel{public String[] name = {"ID","name"};
public int c = 1;
public testtm(String name) {
} public int getRowCount() {
return 0;
} public int getColumnCount() {
return c;
} public String getColumnName(int columnIndex) {
return name[columnIndex];
} public Class getColumnClass(int columnIndex) {
return getValueAt(0,columnIndex).getClass();
} public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
} public Object getValueAt(int rowIndex, int columnIndex) {
return rowIndex+"";
} public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
}//****************************************************************************
public class testeditor implements MouseListener{ private JTable _propertyTable; public testeditor() { }
public void Show(JFrame frame)
{ _propertyTable = new JTable();
_propertyTable.setModel(new testtm("dd"));
_propertyTable.setAutoCreateColumnsFromModel(true);
_propertyTable.getTableHeader().addMouseListener(this);
JScrollPane scorllTable = new JScrollPane(_propertyTable); frame.getContentPane().add(scorllTable);
frame.show();
}
public void mouseClicked(MouseEvent e) {
} public void mouseEntered(MouseEvent e) {
} public void mouseExited(MouseEvent e) {
} public void mousePressed(MouseEvent e) {
//=====更改属性名称
if(e.getSource().equals(_propertyTable.getTableHeader()) &&
e.getClickCount() == 2)
{
testtm t = (testtm)_propertyTable.getModel();
try {
t.fireTableStructureChanged();
}
catch (Exception ex) {
}
}
} public void mouseReleased(MouseEvent e) { }在执行t.fireTableStructureChanged();以后 程序报
java.lang.ArrayIndexOutOfBoundsException: -1
(只有把该事件放到mouse事件中会发生此现象)这怎么可能? 明明什么都没有做.....!!!
public int c = 1;
public testtm(String name) {
} public int getRowCount() {
return 0;
} public int getColumnCount() {
return c;
} public String getColumnName(int columnIndex) {
return name[columnIndex];
} public Class getColumnClass(int columnIndex) {
return getValueAt(0,columnIndex).getClass();
} public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
} public Object getValueAt(int rowIndex, int columnIndex) {
return rowIndex+"";
} public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
}//****************************************************************************
public class testeditor implements MouseListener{ private JTable _propertyTable; public testeditor() { }
public void Show(JFrame frame)
{ _propertyTable = new JTable();
_propertyTable.setModel(new testtm("dd"));
_propertyTable.setAutoCreateColumnsFromModel(true);
_propertyTable.getTableHeader().addMouseListener(this);
JScrollPane scorllTable = new JScrollPane(_propertyTable); frame.getContentPane().add(scorllTable);
frame.show();
}
public void mouseClicked(MouseEvent e) {
} public void mouseEntered(MouseEvent e) {
} public void mouseExited(MouseEvent e) {
} public void mousePressed(MouseEvent e) {
//=====更改属性名称
if(e.getSource().equals(_propertyTable.getTableHeader()) &&
e.getClickCount() == 2)
{
testtm t = (testtm)_propertyTable.getModel();
try {
t.fireTableStructureChanged();
}
catch (Exception ex) {
}
}
} public void mouseReleased(MouseEvent e) { }在执行t.fireTableStructureChanged();以后 程序报
java.lang.ArrayIndexOutOfBoundsException: -1
(只有把该事件放到mouse事件中会发生此现象)这怎么可能? 明明什么都没有做.....!!!
解决方案 »
- 新手求助~急 setVisible(true) 为什么不显示啊
- ==线程问题求救=
- 讨论一些java的小原理!!!!!!
- 菜鸟的小问题,大侠帮个忙
- java怎么打包成别人能执行的程序啊?
- 求java的一个算法或者已完成的类:vox格式转换为的方法
- 关于重写JPanel的paint方法的问题,麻烦大家看看。
- 有大量jar包的时候报错:java.lang.OutOfMemoryError: PermGen space
- 关于jsp开发环境Apache的配置问题??
- 菜鸟问题:java 的帮助,去那里看
- 从给定文件中读取一个整数,并将其进行排序,然后再写入另一个文件中,谢谢,帮助编写一个程序!!
- 一个新手的问题
_propertyTable.getTableHeader().setDraggedColumn(null);