我想问,组件的靠右对齐不是用setAlignment(RIGHT_ALIGNMENT)来设置吗?为什么我设置了还是不行。
我的代码如下: JButton b = new JButton("ddd ");
Box box = Box.createHorizontalBox();
b.setAlignmentX(RIGHT_ALIGNMENT);
box.add(b);
this.add(box,"North");

解决方案 »

  1.   

    建议是看看布局管理器setlayout()那里就详细的介绍了怎样布局!
      

  2.   

    AWT的布局管理方式,理念很先进,但还不是很好用。
      

  3.   

    你把对齐方式设置给了button,那么以后在button上的东西会是右对齐。
    如果想要button靠右,同理。给button的parent组件设置对齐
      

  4.   

    需要看看你的button的容器的布局
      

  5.   


    我对box设置了,还是一样
      

  6.   

     JButton b = new JButton("ddd ");
            Box box = Box.createHorizontalBox();
            b.setLayout(new FlowLayout(FlowLayout.LEFT));
            box.add(b);我想应该是这样的!
      

  7.   


    楼主是不是搞错了,setAlignmentX()方法是JButton中的方法吗?应该是JComponent的方法把?