Example usage for java.awt Component CENTER_ALIGNMENT

List of usage examples for java.awt Component CENTER_ALIGNMENT

Introduction

In this page you can find the example usage for java.awt Component CENTER_ALIGNMENT.

Prototype

float CENTER_ALIGNMENT

To view the source code for java.awt Component CENTER_ALIGNMENT.

Click Source Link

Document

Ease-of-use constant for getAlignmentY and getAlignmentX .

Usage

From source file:BoxLayoutDemo.java

private static JComponent createComponent(String s) {
    JLabel l = new JLabel(s);
    l.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.DARK_GRAY));
    l.setHorizontalAlignment(JLabel.CENTER);
    l.setAlignmentX(Component.CENTER_ALIGNMENT); //use middle of row
    return l;//from   w  w w  .  j a  v a  2s. c om
}

From source file:Main.java

public static void showMessage(String title, String str) {
    JFrame info = new JFrame(title);
    JTextArea t = new JTextArea(str, 15, 40);
    t.setEditable(false);/*from ww w  . j  a  v  a  2s  .  com*/
    t.setLineWrap(true);
    t.setWrapStyleWord(true);
    JButton ok = new JButton("Close");
    ok.addActionListener(windowCloserAction);
    info.getContentPane().setLayout(new BoxLayout(info.getContentPane(), BoxLayout.Y_AXIS));
    info.getContentPane().add(new JScrollPane(t));
    info.getContentPane().add(ok);
    ok.setAlignmentX(Component.CENTER_ALIGNMENT);
    info.pack();
    //info.setResizable(false);
    centerFrame(info);
    //info.show();
    info.setVisible(true);
}

From source file:XAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth();
            int height = getHeight() - insets.top - insets.bottom;
            int halfHeight = height / 2 + insets.top;
            g.drawLine(0, halfHeight, width, halfHeight);
        }//from  www  . j  a  v a 2 s. com
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentY(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentY(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentY(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }/* www  .j  a  v a2 s  .  c  o m*/
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:Main.java

/** Make the given components horizontally-center aligned. */
public static void setHorizontalCenterAlignment(JComponent... components) {
    setAlignmentX(Component.CENTER_ALIGNMENT, components);
}

From source file:layout.BoxLayoutDemo.java

private static void addAButton(String text, Container container) {
    JButton button = new JButton(text);
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    container.add(button);/*  w w  w. ja  v  a 2  s  .  c o m*/
}

From source file:BoxSample.java

private static void changeWidth(JComponent comp) {
    comp.setAlignmentX(Component.CENTER_ALIGNMENT);
    comp.setAlignmentY(Component.CENTER_ALIGNMENT);
    Dimension dim = comp.getPreferredSize();
    dim.width = Integer.MAX_VALUE;
    comp.setMaximumSize(dim);//from w  w w  .j  a v a 2 s .  c o  m
}

From source file:org.championship.manager.license.LicenseDialog.java

public LicenseDialog(Frame owner) throws HeadlessException {
    super(owner, "License", true);

    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(new LicenseEditorPane());
    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(scrollPane);/*from   w w w.  j  a v a  2  s .co m*/

    JButton close = new JButton("Schlieen");
    close.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            LicenseDialog.this.dispose();
        }
    });

    add(Box.createRigidArea(new Dimension(0, 5)));

    close.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(close);

    prepareSize();

    ComponentUtilities.centerComponentOnScreen(this);

    setVisible(true);
}

From source file:unikn.dbis.univis.explorer.license.LicenseDialog.java

public LicenseDialog(Frame owner) throws HeadlessException {
    super(owner, "License", true);

    setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(new LicenseEditorPane());
    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(scrollPane);/*  w  w w  . java 2s .c  o m*/

    JButton close = new JButton(MessageResolver.getMessage(Constants.CLOSE));
    close.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            LicenseDialog.this.dispose();
        }
    });

    add(Box.createRigidArea(new Dimension(0, 5)));

    close.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(close);

    prepareSize();

    ComponentUtilities.centerComponentOnScreen(this);

    setVisible(true);
}

From source file:BoxSample.java

private static void changeHeight(JComponent comp) {
    comp.setAlignmentX(Component.CENTER_ALIGNMENT);
    comp.setAlignmentY(Component.CENTER_ALIGNMENT);
    Dimension dim = comp.getPreferredSize();
    dim.height = Integer.MAX_VALUE;
    comp.setMaximumSize(dim);/*w  w w  .  ja v a  2  s .  co  m*/
}