Example usage for javax.swing JComboBox isVisible

List of usage examples for javax.swing JComboBox isVisible

Introduction

In this page you can find the example usage for javax.swing JComboBox isVisible.

Prototype

@Transient
public boolean isVisible() 

Source Link

Document

Determines whether this component should be visible when its parent is visible.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame result = new JFrame();
    JComboBox<String> combobox = new JComboBox<>(new String[] { "foo", "bar", "aaa", "Hello World" });
    result.add(combobox, BorderLayout.CENTER);

    JCheckBox toggleVisibility = new JCheckBox("Toggle visibility");
    toggleVisibility.setSelected(combobox.isVisible());
    toggleVisibility.addItemListener(e -> {
        combobox.setVisible(e.getStateChange() == ItemEvent.SELECTED);
    });/*from w ww.  j ava  2  s.c  om*/
    result.add(toggleVisibility, BorderLayout.SOUTH);

    result.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    result.pack();
    result.setVisible(true);

}