java NetBeans JTable不带滚动窗格,保留标题
我正在尝试使用NetBeans GUI builder添加一个JTable。桌子在一个已经有滚动条的面板内。Netbeans会在JScrollPane中自动创建所有JTables
但是,我希望表格作为更大页面的一部分滚动。我不需要两个滚动条
我的问题是:如果我去掉滚动窗格,我会丢失标题
有没有办法在Netbeans GUI builder中创建一个带有标题的表
你可以在下面搜索框中键入要查询的问题!
我正在尝试使用NetBeans GUI builder添加一个JTable。桌子在一个已经有滚动条的面板内。Netbeans会在JScrollPane中自动创建所有JTables
但是,我希望表格作为更大页面的一部分滚动。我不需要两个滚动条
我的问题是:如果我去掉滚动窗格,我会丢失标题
有没有办法在Netbeans GUI builder中创建一个带有标题的表
# 1 楼答案
如果
JTable
在JScrollPane
内,则JTableHeader
是(自动)可见的您必须从
JTable
获取JTableHeader
,并通过使用LayoutManager
以编程方式将此对象放置到容器中,我强烈建议对此容器使用BorderLayout
或GridBagLayout
# 2 楼答案
如果直接将
JTabel
添加到容器中(而不是添加到JScrollPane
),则需要自己(以编程方式)添加JTableHeader
,请尝试下一个示例: