错误的垂直框对齐

问题描述 投票:0回答:1

我试图在我的应用程序窗口中对齐一些表。在以下窗口中,所有3个表必须水平填充应用程序窗口区域。相反,3个表中的2个占用应用程序窗口宽度的50%。

JFrame.getContentPane() - > JTabbedPane - > pnlInvoices = Box.createVerticalBox() - >组件错误对齐。

错误排列的组件是JSplitPaneJTableHeaderJTable。创建它的代码如下:

JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
        new JScrollPane(tblInvoices),
        new JScrollPane(tblItems));
sp.setDividerSize(3);
sp.setDividerLocation(75);
Box pnlInvoices = Box.createVerticalBox();
pnlInvoices.add(sp);
JTable tblReport = PropertiesTableModel.createTable(irtm);
pnlInvoices.add(tblReport.getTableHeader());    // JTable must be inside JScrollPane, or else header must be added manually
pnlInvoices.add(tblReport);
//...
JTabbedPane tabs = new JTabbedPane();
//...
tabs.addTab("Τιμολόγια", pnlInvoices);
//...
getContentPane().add(tabs);

The result in application window

java swing
1个回答
0
投票

问题通过黑客解决了。但我不明白为什么。

    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
            new JScrollPane(tblInvoices),
            new JScrollPane(tblItems));
    sp.setDividerSize(3);
    sp.setDividerLocation(75);
    Box pnl = Box.createHorizontalBox();        // Hack
    pnl.add(sp);
    Box pnlInvoices = Box.createVerticalBox();
    pnlInvoices.add(pnl);
    JTable tblReport = PropertiesTableModel.createTable(irtm);
    pnlInvoices.add(tblReport.getTableHeader());
    pnlInvoices.add(tblReport);
© www.soinside.com 2019 - 2024. All rights reserved.