I am trying to add a JTable to a JTabbedPane. It comes up fine, however, the titles for the columns are not visible.
Here’s the relavent bits and pieces of my code:
JTabbedPane jp = new JTabbedPane();
static JTable t1 = new JTable();
static MainFrame f = new MainFrame();
static DefaultTableModel model = new javax.swing.table.DefaultTableModel();
f.scroll.add(jp);
f.scroll.setViewportView(jp);
jp.addTab("Tab 1", null, t1, "");
t1.setModel(model);
model.addColumn("Description");
model.addColumn("Change");
model.setRowCount(1);
model.fireTableStructureChanged();
where f is a JFrame and f.scroll is a JScrollPane
add
JTableto theJScrollPanethenTableHeadershould be visible, then addJScrollPaneto theJTabedpane, otherwise have to addTableHeaderprogramaticallydon’t call
model.fireTableStructureChanged();, this event is correctly implemented in the usedDefaultTableModelbetter could be create columns, the add row, these two values put to the DefaultTableModel (Object or Vector)
add this model to
JTable, e.g.table = new JTable(myModel);