开发者

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();
    }
} );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜