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:Main.java

public static void main(String[] argv) {
    JFrame f = new JFrame();
    f.setLayout(new BorderLayout());

    JPanel panel = new JPanel();
    JButton button = new JButton("A-ha!");
    button.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.add(Box.createVerticalGlue());
    panel.add(button);/*ww  w.ja  va 2s  .  c  om*/
    panel.add(Box.createVerticalGlue());

    f.getContentPane().add(panel);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));

    JPanel a = new JPanel();
    a.setAlignmentX(Component.CENTER_ALIGNMENT);
    a.setPreferredSize(new Dimension(100, 100));
    a.setMaximumSize(new Dimension(100, 100)); // set max = pref
    a.setBorder(BorderFactory.createTitledBorder("aa"));
    JPanel b = new JPanel();
    b.setAlignmentX(Component.CENTER_ALIGNMENT);
    b.setPreferredSize(new Dimension(50, 50));
    b.setMaximumSize(new Dimension(50, 50)); // set max = pref
    b.setBorder(BorderFactory.createTitledBorder("bb"));

    frame.getContentPane().add(a);//from ww w  .  ja v a  2 s  . c o  m
    frame.getContentPane().add(b);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.RED));
    BoxLayout mgr = new BoxLayout(panel, BoxLayout.Y_AXIS);
    panel.setLayout(mgr);/*from  www.ja  v  a 2  s  .  c o m*/
    for (int i = 0; i < 5; i++) {
        JButton button = new JButton("Remove Hello World " + (i + 1));
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        button.addActionListener(e -> {
            panel.remove(button);
            panel.revalidate();
            panel.repaint();
        });
        panel.add(button);
    }
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String labels[] = { "--", "----", "--------", "------------" };

    JPanel container = new JPanel();
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);/*from   w w  w .ja  v a2 s  .co m*/

    for (int i = 0; i < labels.length; i++) {
        JButton button = new JButton(labels[i]);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
    }

    frame.add(container, BorderLayout.CENTER);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:AlignY.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Y Alignment");
    JPanel contentPane = (JPanel) frame.getContentPane();

    BoxLayout layout = new BoxLayout(contentPane, BoxLayout.X_AXIS);
    contentPane.setLayout(layout);/*from   www  . ja  v  a  2 s  .  c  o  m*/

    JButton button = new JButton("0.0");
    button.setAlignmentY(Component.TOP_ALIGNMENT);
    contentPane.add(button);
    button = new JButton("1.0");
    button.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    contentPane.add(button);
    button = new JButton("0.5");
    button.setAlignmentY(Component.CENTER_ALIGNMENT);
    contentPane.add(button);

    frame.setSize(200, 100);
    frame.show();
}

From source file:XAxisAlignY.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = makeIt("Top", Component.TOP_ALIGNMENT);
    Container panel2 = makeIt("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("Bottom", Component.BOTTOM_ALIGNMENT);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 3));
    contentPane.add(panel1);/*  w ww  .  ja  va  2 s  . com*/
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.setSize(423, 171);
    frame.setVisible(true);
}

From source file:XAxisAlignY.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = layoutComponents("Top", Component.TOP_ALIGNMENT);
    Container panel2 = layoutComponents("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = layoutComponents("Bottom", Component.BOTTOM_ALIGNMENT);

    frame.setLayout(new GridLayout(1, 3));
    frame.add(panel1);//  w  w w  .  j a  va  2s.  c  om
    frame.add(panel2);
    frame.add(panel3);

    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:YAxisAlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = makeIt("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = makeIt("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("Right", Component.RIGHT_ALIGNMENT);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);//from  w  w  w . j av  a 2  s . co m
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.pack();
    frame.setVisible(true);
}

From source file:YAxisAlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Alignment Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container panel1 = layoutComponents("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = layoutComponents("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = layoutComponents("Right", Component.RIGHT_ALIGNMENT);
    frame.setLayout(new FlowLayout());
    frame.add(panel1);//ww  w.j  av  a2  s.c  o  m
    frame.add(panel2);
    frame.add(panel3);

    frame.pack();
    frame.setVisible(true);
}

From source file:AlignX.java

public static void main(String args[]) {
    JFrame frame = new JFrame("X Alignment");
    Container contentPane = frame.getContentPane();

    Container panel1 = makeIt("R", Component.RIGHT_ALIGNMENT);
    Container panel2 = makeIt("C", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("L", Component.LEFT_ALIGNMENT);

    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);//from www .  j a va2 s . co  m
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.pack();
    frame.show();
}