opike
opike

Reputation: 7585

Java: Issue with jsplitpane and boxlayout

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);

Upvotes: 2

Views: 1121

Answers (1)

camickr
camickr

Reputation: 324128

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.

Upvotes: 5

Related Questions