/*
 *  功能:JCombobox和JList的使用
 */
package com.swing;
import java.awt.GridLayout;
import javax.swing.*;
     
class jcombobox extends JFrame{
    public static void main(String[] args){
        jcombobox jbox=new jcombobox();
    }
    public jcombobox(){
            
        JLabel jl1=new JLabel("籍贯");
        JLabel jl2=new JLabel("现在所在城市");
            
        JPanel jp1,jp2;
            
        String[] jiguan={"湖南","江苏","广州"};
        String[] city={"北京","上海","长沙","深圳","南京"};
        JComboBox box1=new JComboBox(jiguan);
        JList jlist=new JList(city);
        jlist.setVisibleRowCount(3);
        //设置滚动控件
        JScrollPane jsp=new JScrollPane(jlist);
            
        //设置风格布局
        this.setLayout(new GridLayout(2,1));
        //设置第一块面板
        jp1=new JPanel();
        jp1.add(jl1);
        jp1.add(box1);
        this.add(jp1);
        //设置第二块面板
        jp2=new JPanel();
        jp2.add(jl2);
        jp2.add(jsp);
        this.add(jp2);
            
            
            
        this.setTitle("JComboBox的使用");
        this.setSize(200,200);
        this.setLocation(100,100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
}

java JCombobox和JList的使用_import