gpt4 book ai didi

java - JFrame 布局不一致

转载 作者:行者123 更新时间:2023-11-30 09:38:42 25 4
gpt4 key购买 nike

我有一个 JFrame,它显示两个 JSplitPanes(一个在另一个里面)。

For some reason the divider location is inconsistent.

我的意思是有时它会显示在我设置的正确位置,而有时则不会。当位置错误时,两个拆分面板都是错误的。这是我用于 JSplitPanes 的代码:

        JPanel javaPanel = core.getComponentPanel(2);
JSplitPane splitA = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
javaPanel.getComponent(0), javaPanel.getComponent(1));
double pos = (screenDim.getHeight() * 72) / 100;
splitA.setDividerLocation((int) pos);
JSplitPane mainSplitP = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(getCoreComponents()), splitA);
return mainSplitP;

在 JFrame 上,我有一个带有 CardLayout 的 JPanel。要添加 mainSplitP,我使用以下方法:

    private void setFrameContent(Container content, String title) {
appContent.add(content, title);
CardLayout cl = (CardLayout) (appContent.getLayout());
cl.show(appContent, title);
appFrame.pack();
}

是什么导致了这种不一致?

最佳答案

关于java - JFrame 布局不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10012461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com