我在 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));
}
}
最佳答案
有两种方法
(正确的方法)必须将
<JTable
放到JScrollPane
中,然后JTableHeader
可见从
JTable
获取JTableHeader
(将JPanel
的LayoutManager
更改为BorderLayout
) 并放入JPanel
中的
NORTH area
关于java - 我没有得到列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13721611/