comboboxsample.java

来自「The Definitive Guide to Java Swing, Thir」· Java 代码 · 共 30 行

JAVA
30
字号
import java.awt.*;
import javax.swing.*;
public class ComboBoxSample {
  public static void main(final String args[]) {
    Runnable runner = new Runnable() {
      public void run() {
    String labels[] = {"Chardonnay", "Sauvignon", "Riesling", "Cabernet",
      "Zinfandel", "Merlot", "Pinot Noir", "Sauvignon Blanc", "Syrah",
      "Gew黵ztraminer"};

    String title = (args.length==0 ? "Example JComboBox" : args[0]);
    JFrame frame = new JFrame(title);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JComboBox comboBox1 = new JComboBox(labels);
    comboBox1.setMaximumRowCount(5);
    frame.add(comboBox1, BorderLayout.NORTH);

    JComboBox comboBox2 = new JComboBox(labels);
    comboBox2.setEditable(true);
    frame.add(comboBox2, BorderLayout.SOUTH);

    frame.setSize(300, 200);
    frame.setVisible(true);
      }
    };
    EventQueue.invokeLater(runner);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?