Example usage for javax.swing BoxLayout getLayoutAlignmentY

List of usage examples for javax.swing BoxLayout getLayoutAlignmentY

Introduction

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

Prototype

public synchronized float getLayoutAlignmentY(Container target) 

Source Link

Document

Returns the alignment along the Y 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.getLayoutAlignmentY(container));
    container.setLayout(layout);/*  ww  w .ja va  2s  . c  o  m*/

    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();/*from w  w w . j a va  2s.  co  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);
        }
    }
}