The components I want to pace onto the JPanel on the left side of a JSplitPane are note arranged as expected when using BoxLayout. Why not? When I am using JButtons only they are aligned left but as soon as I place another component onto the JPanel the alignment plays up.
private void initGuiComponents()
{
//The layout of the application itself.
this.getContentPane().setLayout(new BorderLayout());
//NORTH components
openFileButton = new JButton(openFileButtonStr);
groupCriterionChooser = new JComboBox();
fileloadProgresslabel = new JLabel(fileloadProgressStr);
fileloadProgressbar = new JProgressBar();
fileloadProgressbar.setStringPainted(true);
topPane.setLayout(new FlowLayout(FlowLayout.LEADING));
topPane.add(openFileButton);
topPane.add(fileloadProgresslabel);
topPane.add(fileloadProgressbar);
this.getContentPane().add(topPane, BorderLayout.PAGE_START);
//CENTER components
JScrollPane mainScrollPane = new JScrollPane(mainPane);
{
//RIGHT JSplitPane components
BoxLayout bl = new BoxLayout(mainPane, BoxLayout.PAGE_AXIS);
mainPane.setLayout(bl);
mainPane.setBackground(Color.orange);
//LEFT JSplitPane components
leftNavPane.setLayout(new BoxLayout(leftNavPane, BoxLayout.PAGE_AXIS));
leftNavPane.setBorder(BorderFactory.createEmptyBorder(10,0,10,10));
leftNavPane.setBackground(Color.green);
JButton b1 = new JButton("111");
b1.setAlignmentX(LEFT_ALIGNMENT);
leftNavPane.add(b1);
leftNavPane.add(Box.createRigidArea(new Dimension(0,5)));
JButton b2 = new JButton("222");
b2.setAlignmentX(LEFT_ALIGNMENT);
leftNavPane.add(b2);
leftNavPane.add(Box.createRigidArea(new Dimension(0,5)));
traceGroupJumperList = new JList();
traceGroupJumperList.setAlignmentY(RIGHT_ALIGNMENT);
leftNavPane.add(traceGroupJumperList);
traceGroupJumperList.add(new JLabel("cc"));
java.util.Vector v = new java.util.Vector();
v.add(new String("aaa"));
v.add(new String("zzz"));
traceGroupJumperList.setListData(v);
traceGroupJumperList.revalidate();
traceGroupJumperList.repaint();
/*
leftNavPane.setLayout(new BoxLayout(leftNavPane, BoxLayout.PAGE_AXIS));
leftNavPane.setAlignmentY(leftNavPane.LEFT_ALIGNMENT);
leftNavPane.setBorder(BorderFactory.createEmptyBorder(10,0,10,10));
java.util.Vector v = new java.util.Vector();
v.add(new String("aaa"));
v.add(new String("zzz"));
traceGroupJumperList = new JList(v);
traceGroupJumperList.setAlignmentY(this.LEFT_ALIGNMENT);
JButton b3 = new JButton("33333");
b3.setAlignmentY(LEFT_ALIGNMENT);
b3.setBackground(Color.green);
leftNavPane.add(b3);
leftNavPane.add(Box.createRigidArea(new Dimension(1, 10)));
leftNavPane.add(traceGroupJumperList);
leftNavPane.add(Box.createRigidArea(new Dimension(1, 10)));
JButton b4 = new JButton("44444");
b4.setAlignmentY(RIGHT_ALIGNMENT);
leftNavPane.add(b4);
*/
}
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
leftNavPane, mainScrollPane);
//SOUTH components
statusPane = new JPanel();
//Putting it altogether
this.getContentPane().add(statusPane, BorderLayout.SOUTH);
this.getContentPane().add(splitPane, BorderLayout.CENTER);
addListeners();
}//end initGuiComponents
//----------------------------------------------------------------------------
modulo
Community Support Moderator
Experts Exchange