我正在创建一个表,用户可以在其中更改标题并根据其意愿添加列等,但是当用户向表中添加新列时会出现问题。最近编辑的列一直到末尾,其标题显示的文本类似“ Ljava.lang.String:@ ...”,其中“ ...” =一些字母和数字。
public class StudentsStats {
static JFrame frame = new JFrame("StudentsStats");
static String data[][] = {};
static String row[] = {"Sr.No","Adm.No","Name", "","","","","","","","",""};
static DefaultTableModel model = new DefaultTableModel(data, row);
static JTable table = new JTable(model);
static TableColumn tabCol;
public static void tableView(){
JScrollPane pane = new JScrollPane(table);
JTableHeader header = table.getTableHeader();
TableColumnModel colModel = header.getColumnModel();
header.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2){
int col = colModel.getColumnIndexAtX(e.getX());
tabCol = colModel.getColumn(col);
String str = JOptionPane.showInputDialog("Enter a name for this column.");
tabCol.setHeaderValue(str);
header.repaint();
}
}
});
frame.add(pane);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void addcolumn(){
String col[] = {};
model.addColumn(col);
}