Код: Выделить всё
import javax.swing.*;
import java.awt.*;
public class ComboBoxMVCExample {
public static void main (String[] args) throws Exception {
SwingUtilities.invokeLater(ComboBoxMVCExample::createAndShowGUI);
}
private static void createAndShowGUI () {
LookAndFeel laf = UIManager.getLookAndFeel();
System.out.println("Look and Feel name: " + laf.getClass().getName());
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] items = {"Apple", "Banana"};
JComboBox editableCombo = new JComboBox(items);
editableCombo.setEditable(true);
JComboBox nonEditableCombo = new JComboBox(items);
nonEditableCombo.setEditable(false);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
panel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 4));
panel.add(new JLabel("Editable"));
panel.add(editableCombo);
panel.add(new JLabel("Not Editable"));
panel.add(nonEditableCombo);
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... il-java-20
Мобильная версия