http://blog.csdn.net/sting2005/archive/2007/03/13/1527953.aspx
JTable组件显示数据时,如果直接将其放置在Frame的contentPane中则表头一行会显示不出来,如果将其放置在JScrollPane中显示数据的话,表头会自动显示出来。
引用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 scrolls 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表头合并, 很方便使用,swing的控件,下载下来,直接导入工程就可以使用了,接口封装的很好。想要什么样的表头都可以满足你
复杂JTable(复杂表头、跨行列表体)
复杂JTable-跨列表头, JTable表头合并,已经测试Ok,希望对你有用
在开发swing时,JTble不显示表头的问题
jtable swing jtableheader netbeans 复杂表头 表头合并 使用netbeans打开后可以打开JFrame
JTable的自动换行。挺好用的。里面还可以设置字体大小。分享一下。
一个JTable里添加CheckBox的完整例子,包括表头的JCheckBox全选联动
中级SWING-J中级中级SWING-JTable属性SWING-JTable属性Table属性
介绍了jtable中加入复选的难点的俩个例子,方便大家更好的学习.
Jtable表格排序,这两天公司让做一个Jtable表格的排序,首先按A列排序,在A列相等时按B列排序,B列相等时按C列排序,ABC三列可以任意指定,最多分三列,这样的一个需求。
里面包含有很全的JTable实例,如合并表头,合并表格,等等,已经打包成JAR
网上的JTable的例子,共25个,已全部调试通过,包括JTable多级表头,多级行头,合并单元格等
//JTable jTable1 = new JTable(); public JTable jTable1=null; private JTree jTree1; DefaultTableModel mode; private JScrollPane scrollPane = null; DefaultMutableTreeNode node; JButton[] btn={...
import javax.swing.*; import javax.swing.event.*; import java.util.*; import java.sql.*; import java.sql.Statement; import javax.swing.table.*; import javax.swing.tree.*; /** * * @...
实例045 用数组设置JTable表格的列名与列宽 55 3.2 数组操作 57 实例046 数组的下标界限 57 实例047 按钮控件数组实现计数器界面 58 实例048 复选框控件数组 59 实例049 用数组反转字符串 60 3.3 数组排序与查询 61 ...