// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*; 
import java.util.stream. IntStream;
import javax.swing.*; 

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    JComboBox<String> comboBox = new JComboBox<>(makeModel());

    SpinnerNumberModel m = new SpinnerNumberModel(comboBox.getMaximumRowCount(), -1, 1000, 1);
    m.addChangeListener(e -> comboBox.setMaximumRowCount(m.getNumber().intValue()));
    JSpinner spinner = new JSpinner(m);

    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createTitledBorder("JComboBox#setMaximumRowCount:"));
    p.add(spinner);

    Box box = Box.createVerticalBox();
    box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    box.add(p);
    box.add(Box.createVerticalStrut(10));
    box.add(comboBox);

    add(box, BorderLayout. NORTH);
    setPreferredSize(new Dimension(320, 240));
  }

  private static DefaultComboBoxModel<String> makeModel() {
    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>();
    IntStream.range(0, 100).forEach(i -> model.addElement("Item" + i));
    return model;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants. EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}
