问题描述
所以我有一堆 JTable
。每个 JTable
都在 JScrollPane
中。然后我将这些 JScrollPane
中的每一个添加到 JPanel
。然后我将 JPanel
添加到 JScrollPane
然后再添加到另一个 JPanel
with BorderLayout
。较大的 JScrollPane
使用其父级正确调整大小,但每个较小的 JScrollPane
都有不变的高度,大于窗口很小的时候。我怎样才能让每个孩子 JScrollPane
用窗口/父母的高度来调整大小?
So I have a bunch of JTable
s. Each JTable
is inside a JScrollPane
. I'm then adding each of these JScrollPane
s to a JPanel
. I'm then adding this JPanel
to a JScrollPane
then that to another JPanel
with BorderLayout
. The larger JScrollPane
properly resizes with its parent, but each of the smaller JScrollPane
s have constant height, which is larger than the window when it is small. How can I get each of the children JScrollPane
s to resize with the height of the window/their parent?
我尝试使用 FlowLayout
添加更多中介 JPanel
, BorderLayout
,似乎没有任何效果。
I've tried adding more intermediary JPanel
s with FlowLayout
, BorderLayout
, and nothing seems to work.
以下是一些相关代码:
public class MyPanel extends JPanel
{
public MyPanel()
{
super(new BorderLayout());
JPanel panel = new JPanel();
for (int i = 0; i < 5; i++)
{
// View extends JTable
panel.add(new JScrollPane(new View(new Model())));
}
add(new JScrollPane(panel));
}
}
我真的只是想得到一堆带有滚动条的表格在一个带有水平滚动条的较大面板内水平相邻。当窗口大小发生变化时,我希望所有内容都适当调整大小。
I'm really just trying to get a bunch of tables with scrollbars horizontally next to each other inside a larger panel with a horizontal scrollbar. And I want all that stuff to resize appropriately when the window size changes.
更多代码:
final MyPanel panel = new MyPanel();
final JTabbedPane tabView = new JTabbedPane();
tabView.add(...);
tabView.add("foo", panel);
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, ..., tabView);
this.add(splitPane); // this extends JFrame
推荐答案
你可以使用。如果您想要相反:某些表被修复,您可以使用约束。
You can use a BoxLayout. If you want the opposite: some table being fixed, you can wrap it with constraint Box.createRigidArea(new Dimension(100, 100)) .
这篇关于如何在JScrollPane中获取JScrollPanes以跟随父级的大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!