2

I have a JFrame which displays two JSplitPanes (one inside the other).

For some reason the divider location is inconsistent.

What I mean by that is that sometimes its displayed on the correct position where I have set it, while other times it doesn't. When the position is wrong, its wrong for both split panels. Here is the code I am using for the 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;

On the JFrame I have a JPanel with CardLayout. To add the mainSplitP I use the following method:

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

What could be causing this inconsistency ?

Giannis
  • 5,286
  • 15
  • 58
  • 113

1 Answers1

2
Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Had to add some ugly code with casting but at least it works. Thanks ! – Giannis Apr 04 '12 at 14:16
  • One more thing. Is there a way to have the divider location based on the preferred size of the components the JSplitPane contains ? That way since my components got a set preferred size I might not need to set the location manually ? – Giannis Apr 04 '12 at 14:23