我不知道为什么列名被命名为“A”、“B”、“C”......在刷新 JTable 之后。
我创建了一个类来刷新 JTable。
public class TableModelClass extends AbstractTableModel
{
Object[][] data;
Object[] title;
public TableModelClass(Object[][] dat, Object[] tit)
{
data = dat;
title = tit;
}
@Override
public int getColumnCount()
{
if(title != null)
return title.length;
return 0;
}
@Override
public int getRowCount()
{
if(data != null)
return data.length;
return 0;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex)
{
return data[rowIndex][columnIndex];
}
}
我在课堂上设置了默认的 JTables 值:
Object[] titlesDefault = { "tit1", "tit12","tit3"};
Object[][] dataDefault = {{ "1", "2","3"},
{"1", "2","3"}};
_jTable = new JTable(dataDefault, titlesDefault);
_bAddTable.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
try
{
Object[] titles2 = { "1", "2","3", "1", "2","3"};
Object[][] data = {{ "1", "2","3"},
{ "1", "2","3"},
{"1", "2","3"}};
data.setModel(new TableModelClass(data, titles2));
}
catch (ClassNotFoundException)
{
e1.printStackTrace();
}
};
});
在此之后,我收到列名中的字母。为什么?