小编典典

JTable将不显示列标题

javascript

我有以下代码实例化JTable:该表具有正确数量的行和列,但是在列顶部没有标题的迹象。

public Panel1()
{
    int  nmbrRows;

    setLayout(null);
    setBackground(Color.magenta);
    Vector colHdrs;

    //create column headers

    colHdrs = new Vector(10);
    colHdrs.addElement(new String("Ticker"));

    // more statements like the above to establish all col. titles       

    nmbrRows = 25;
    DefaultTableModel tblModel = new DefaultTableModel(nmbrRows, colHdrs.size());
    tblModel.setColumnIdentifiers(colHdrs);

    scrTbl = new JTable(tblModel);
    scrTbl.setBounds(25, 50, 950, 600);
    scrTbl.setBackground(Color.gray);
    scrTbl.setRowHeight(23);    
    add(scrTbl);

//rest of constructor
...

}

与其他制表代码相比,我看不到任何遗漏的步骤,但是必须缺少某些内容。


阅读 365

收藏
2020-09-23

共1个答案

小编典典

把你的JTable里面JScrollPane。试试这个:

add(new JScrollPane(scrTbl));
2020-09-23