Using the Visual Editor in Eclipse I started a Swing UI containing a table (JTable) with 2 columns (JTableColumn). Adding data to the table this way:
final DefaultTableModel model = (DefaultTableModel) this.jTable.getModel();
model.addRow(new Object[] {"Column 1", "Column 2"});
generated an ArrayIndexOutOfBoundsException. I solved this by setting the number of columns of the model backing the table:
model.setColumnCount(this.jTable.getColumnCount());
But after this call, the column headers of the table I defined using the UI editor, are changed to "A" and "B". Now I'm wondering if I should go on and correct the generated code like I did, or is there a better way to build UI's with Visual Editor?
To be complete, this is the generated code to define the table and columns:
private JTable getJTable() {
if (this.jTableSongs == null) {
final TableColumn tableColumn1 = new TableColumn();
tableColumn1.setHeaderValue("Header 1");
final TableColumn tableColumn2 = new TableColumn();
tableColumn2.setHeaderValue("Header 2");
this.jTableSongs = new JTable();
this.jTableSongs.addColumn(tableColumn1);
this.jTableSongs.addColumn(tableColumn2);
}
return this.jTable;
}
I don't know about this specific problem (table columns) but in the past i had similar problems with VE.
If you don't have the number of columns in the Property View, you have to specify it programmatically, editing the code, but VE will not remove hand added code.