reseting a flow layout with a button
What I am trying to do here is set the layout scheme once I pr开发者_StackOverflow社区ess 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?
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();
}
} );
精彩评论