如何在JScrollPane中获取JScrollPanes以跟随父级的大小调整 [英] How to get JScrollPanes within a JScrollPane to follow parent's resizing

查看:156
本文介绍了如何在JScrollPane中获取JScrollPanes以跟随父级的大小调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一堆 JTable 。每个 JTable 都在 JScrollPane 中。然后我将这些 JScrollPane 中的每一个添加到 JPanel 。然后我将 JPanel 添加到 JScrollPane 然后再添加到另一个 JPanel with BorderLayout 。较大的 JScrollPane 使用其父级正确调整大小,但每个较小的 JScrollPane 都有不变的高度,大于窗口很小的时候。我怎样才能让每个孩子 JScrollPane 用窗口/父母的高度来调整大小?

So I have a bunch of JTables. Each JTable is inside a JScrollPane. I'm then adding each of these JScrollPanes 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 JScrollPanes have constant height, which is larger than the window when it is small. How can I get each of the children JScrollPanes to resize with the height of the window/their parent?

我尝试使用 FlowLayout 添加更多中介 JPanel BorderLayout ,似乎没有任何效果。

I've tried adding more intermediary JPanels 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


推荐答案

你可以使用 BoxLayout 。如果您想要相反:某些表被修复,您可以使用约束 Box.createRigidArea(new Dimension(100,100))

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以跟随父级的大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆