我在JPanel
中放置JTable
,但是當我顯示時,我看到表格內容但看不到列名稱。我沒有得到列的名稱
public class Neww extends JPanel
{
Connection conn = null;
Statement st;
DefaultTableModel model = new DefaultTableModel(new Object[][] {
{ " ", " " },
{ " ", " " },
{ " ", " " },
{ " ", " " },
{ " ", " " },
{ " ", " " }
}, new Object[] {
"ItemName",
"No of items"
});
JTable table = new JTable(model);
TableColumn ItemName = table.getColumnModel().getColumn(0);
JComboBox comboBox = new JComboBox();
Neww()
{
this.setLayout(new FlowLayout(FlowLayout.CENTER));
this.add(table);
comboBox.addItem("Spoon");
comboBox.addItem("Plate");
comboBox.addItem("Mixer");
comboBox.addItem("Glass");
ItemName.setCellEditor(new DefaultCellEditor(comboBox));
}
}
+1打我吧 –