开发者

reseting a flow layout with a button

开发者 https://www.devze.com 2022-12-14 02:40 出处:网络
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

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

精彩评论

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