views:

20

answers:

1

What I am trying to do here is set the layout scheme once I press a button to align all the buttons to the left of the contentPane I have three buttons this is the code i have for that particular button

  leftButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
   cp.setLayout( new FlowLayout(FlowLayout.LEFT));

  }
 } );

it also compiles just find but dont align anything to the left. Must I add more to this code or should this do it?

+1  A: 

After you have set the new LayoutManager, you need to call revalidate() on the container. So from your code, something like the following should work.

leftButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        cp.setLayout( new FlowLayout(FlowLayout.LEFT));
        cp.revalidate();
    }
} );
Damien Ayers