Question

I want to get rid of the empty space to the left of the jsplitpanes:

screenshot

Here's my code:

getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane.add(downloadsPanel);
splitPane.add(filesPanel);

JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
splitPane2.add(processingPanel);
splitPane2.add(messagePanel);

JSplitPane splitPane3 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

splitPane3.add(splitPane);
splitPane3.add(splitPane2);

getContentPane().add(addPanel);
getContentPane().add(splitPane3);
Was it helpful?

Solution

BoxLayout does weird things with the alignment of components. Read the section from the swing tutorial on Fixing Alignment Problems. In short, make sure the alignment of the addPanel and splitPane3 are the same:

component.setAlignmentX(Component.CENTER_ALIGNMENT);

It looks to me like one defaults to CENTER and the other defaults to LEFT.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top