Example usage for javax.swing GroupLayout setHonorsVisibility

List of usage examples for javax.swing GroupLayout setHonorsVisibility

Introduction

In this page you can find the example usage for javax.swing GroupLayout setHonorsVisibility.

Prototype

public void setHonorsVisibility(boolean honorsVisibility) 

Source Link

Document

Sets whether component visibility is considered when sizing and positioning components.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);/*from   w w  w . j  a  v  a 2  s  .co m*/

    gl.setAutoCreateGaps(true);
    gl.setAutoCreateContainerGaps(true);

    JButton btn = new JButton("Switch");
    btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < 9; i++) {
                labels[i].setVisible(!labels[i].isVisible());
            }
        }
    });

    gl.setHonorsVisibility(false);

    SequentialGroup seqGroup = gl.createSequentialGroup();
    gl.setHorizontalGroup(seqGroup);
    seqGroup.addComponent(btn);
    seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    for (int i = 0; i < 10; i++) {
        seqGroup.addComponent(labels[i]);
        seqGroup.addPreferredGap(ComponentPlacement.UNRELATED, 10, 10);
    }
    ParallelGroup parGroup = gl.createParallelGroup();
    gl.setVerticalGroup(parGroup);
    parGroup.addComponent(btn);

    for (int i = 0; i < 10; i++) {
        parGroup.addComponent(labels[i]);
    }
    pack();
}