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 ?
JComponents
knows own size after pack()
, or when they're once time visible on the screen