JTable 不会显示列标题 [英] JTable won't show column headers
本文介绍了JTable 不会显示列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来实例化 JTable:该表提供了正确的行数和列数,但列顶部没有标题的迹象.
I have the following code to instantiate a JTable: the table comes up with the right number of rows and columns, but there is no sign of the titles atop the columns.
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
...
}
将此与其他制表代码进行比较,我没有看到任何缺失的步骤,但必须缺少某些东西.
Comparing this to other table-making code, I don't see any missing steps, but something must be absent.
推荐答案
将您的 JTable
放在 JScrollPane
中.试试这个:
Put your JTable
inside a JScrollPane
. Try this:
add(new JScrollPane(scrTbl));
这篇关于JTable 不会显示列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文