Example usage for javax.swing BoxLayout getLayoutAlignmentX

List of usage examples for javax.swing BoxLayout getLayoutAlignmentX

Introduction

In this page you can find the example usage for javax.swing BoxLayout getLayoutAlignmentX.

Prototype

public synchronized float getLayoutAlignmentX(Container target) 

Source Link

Document

Returns the alignment along the X axis for the container.

Usage

From source file:Main.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);
    System.out.println(layout.getLayoutAlignmentX(container));
    container.setLayout(layout);/*from w  w w.j a v  a 2 s  .  c om*/

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

    frame.add(container, BorderLayout.CENTER);

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

From source file:BoxLayoutVerticalGlueTest.java

public void paintChildren(Graphics g) {
    super.paintChildren(g);
    Dimension size = getSize();/*w w w  . ja  v  a  2  s.  c o m*/
    LayoutManager manager = getLayout();
    if ((manager != null) && (manager instanceof BoxLayout)) {
        BoxLayout layout = (BoxLayout) manager;
        boolean vertical = true;
        if (vertical) {
            int axis = (int) (layout.getLayoutAlignmentX(this) * size.width);
            g.fillRect(axis - 1, 0, 3, size.height);
        } else {
            int axis = (int) (layout.getLayoutAlignmentY(this) * size.height);
            g.fillRect(0, axis - 1, size.width, 3);
        }
    }
}