引用Sun的原话为:
It's easy to put a table in a scroll pane. You need just one or two lines of code:
JScrollPane scrollPane = new JScrollPane(table)
table.setPreferredScrollableViewportSize(new Dimension(500, 70))
The scroll pane automatically gets the table's header, which displays the column names, and puts it on top of the table. Even when the user scroll户孩膏绞薇悸疙溪躬娄s down, the column names remain visible at the top of the viewing area. The scroll pane also tries to make its viewing area the same as the table's preferred viewing size. The previous code snippet sets the table's preferred viewing size with the setPreferredScrollableViewportSize method.
If you're using a table without a scroll pane, then you must get the table header component and place it yourself. For example:
container.setLayout(new BorderLayout())
container.add(table.getTableHeader(), BorderLayout.PAGE_START)
container.add(table, BorderLayout.CENTER)在使用时要注意!
JTable必须有JScrollPane包裹才能显示出表头,在构造函数public Maindemo()中加一句JScrollPane jsp = new JScrollPane(table)
把c.add(this.table,BorderLayout.CENTER)改成c.add(this.jsp,BorderLayout.CENTER)
就可以显示出表头了.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)