开发者

What parameters can Java setAlignment Function have?

开发者 https://www.devze.com 2023-01-11 19:08 出处:网络
What are the parameters that can be passed in setAlignment Function. Also what does this button1.setAlignment(1f) mean .

What are the parameters that can be passed in setAlignment Function. Also what does this button1.setAlignment(1f) mean .

For Example

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("C开发者_运维百科lose");

        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);

    }


I think you are talking about setAlignmentX(1f) method. This method is defined in JComponent class. It sets the the vertical alignment.

http://download.oracle.com/javase/1.5.0/docs/api/javax/swing/JComponent.html#setAlignmentX(float)

Possible values for setAlignmentX are 

Component.CENTER_ALIGNMENT  0.5f
Component.LEFT_ALIGNMENT    0.0f
Component.RIGHT_ALIGNMENT   1.0f

In your case it is "1f" so this component has (Component.RIGHT_ALIGNMENT) Right vertical alignment

Box.createRigidArea Creates an invisible component that's always the specified size.


All methods in Java belong to a class, and as it is (without the class name) I have no idea which method you're talking about.

If you do know the class name, and it's a core Java class, then check out the official API for a list of all of the classes and methods involved in the J2SE API. Just find the class you're interested in on the left hand side, click on it and you'll see a list of all its methods, together with documentation and parameter lists.

If it's not a core Java class then you'll need to find the API for the library that defines it. Almost all commonly-downloadable libraries will have an "API" or "Javadocs" link on their homepage that you can follow to achieve the same thing as above.

And if you don't know the class name, that's the first thing to find out. (Without it your question is like asking "Who lives at house number 34?" You'll need the street name and quite possibly town name to get an answer without the specific context.)

0

精彩评论

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