什麼是可以在setAlignment函數中傳遞的參數。此外button1.setAlignment(1f)
是什麼意思。Java的setAlignment函數有什麼參數?
對於實例
public class TwoButtons extends JFrame {
public TwoButtons() {
setTitle("Two Buttons");
JPanel basic = new JPanel();
basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
add(basic);
basic.add(Box.createVerticalGlue());
JPanel bottom = new JPanel();
bottom.setAlignmentX(1f);
bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
JButton ok = new JButton("OK");
JButton close = new JButton("Close");
bottom.add(ok);
bottom.add(Box.createRigidArea(new Dimension(5, 0)));
bottom.add(close);
bottom.add(Box.createRigidArea(new Dimension(15, 0)));
basic.add(bottom);
basic.add(Box.createRigidArea(new Dimension(0, 15)));
setSize(300, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
也請告訴我那個Box.createRigidArea是什麼 – subanki 2010-08-17 16:58:45
更新了我的回答關於Box.createRigidArea的信息 – YoK 2010-08-18 12:00:43