Example usage for javax.swing BoxLayout invalidateLayout

List of usage examples for javax.swing BoxLayout invalidateLayout

Introduction

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

Prototype

public synchronized void invalidateLayout(Container target) 

Source Link

Document

Indicates that a child has changed its layout related information, and thus any cached calculations should be flushed.

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);
    layout.invalidateLayout(container);
    container.setLayout(layout);/* w  w  w. ja v a2  s.  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);
}