Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.event.ItemEvent;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;

public class Main {
    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);
        });
        result.add(toggleVisibility, BorderLayout.SOUTH);

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

    }
}