Reputation: 99
Hey I don't have enough knowledge on JTables
, How to insert data in JTables
by the way I entered the data in my table but I don't know why the column names not appear in my table.
Here's my code:
public class tab {
public tab() {
initComponents();
}
public void initComponents() {
JFrame fr = new JFrame("Score Card");
JScrollPane pane = new JScrollPane();
fr.setSize(500, 350);
JTable scoreTab = new JTable(5, 4);
DefaultTableModel model = new DefaultTableModel(1, 4);
// model.setColumnIdentifiers(new Object[]{"No","Name","Score","Date"});
scoreTab.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] { { 1, 2, 2 },
}, new String[] { "Name", "Score", "Date" }));
pane.setViewportView(scoreTab);
fr.add(scoreTab);
fr.setLocationRelativeTo(null);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setVisible(true);
}
public static void main(String[] args) {
new tab();
}
}
Upvotes: 0
Views: 785
Reputation: 9872
add JScrollPane
to the jframe
fr.add(pane);
you are directly adding jtable to the frame fr.add(scoreTab);
if you add a table without jscrollpane you have to add headers separately.
Upvotes: 2