I am having a problem with left alignment after adding a second JPanel. Both JPanels are using the BoxLayout with the first set to Y_AXIS and the second set to X_AXIS. If you comment out the add(twoPanel) it results in the desired left alignment. I don't understand why the alignment changes after adding the second JPanel. Thanks in advance.
import javax.swing.*;
public class BoxManager extends JApplet{
JButton one, two, three;
public void init() {
one = new JButton("one");
two = new JButton("two");
three = new JButton("three");
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
add(new JLabel("This is the contentPane."));
JPanel twoPanel = new JPanel();
twoPanel.setLayout(new BoxLayout(twoPanel, BoxLayout.X_AXIS));
twoPanel.add(new JLabel("Second Panel"));
twoPanel.add(new JTextField("Text Field"));
add(twoPanel); // comment this line out
add(one);
add(two);
add(three);
}
}