Java布局管理器能让某个组件居中么?

解决方案 »

  1.   

    当然能了 ,borderlayout应该就可以满足你的要求。
      

  2.   

    当然可以,BorderLayout就有Center属性!
      

  3.   


    import java.awt.BorderLayout;import javax.swing.JButton;
    import javax.swing.JFrame;
    public class Test  extends JFrame { public Test() {
    this.setTitle("Demo");
    this.setBounds(400, 300, 400, 300);
    this.setDefaultCloseOperation(3);
    this.setLayout(new BorderLayout());
    this.add(new JButton("west"), BorderLayout.WEST);
    this.add(new JButton("east"), BorderLayout.EAST);
    this.add(new JButton("north"), BorderLayout.NORTH);
    this.add(new JButton("south"), BorderLayout.SOUTH);
    this.add(new JButton("center"), BorderLayout.CENTER);
    this.setVisible(true);
    }

    public static void main(String[] args) {
    new Test();
    }

    }