/**
* 作者:
* 日期:2013-11-19
* 功能:JComboBox列表框 JList下拉框
*/
package com.ch;
import java.awt.*;
import javax.swing.*;
public class Demo10 extends JFrame{
//定义使用的组件
JPanel jp1,jp2;
JLabel jl1,jl2;
JComboBox jcb1;
JList jlist;
JScrollPane jsp;
public Demo10(){
jp1 = new JPanel();
jp2 = new JPanel();
jl1 = new JLabel("籍贯");
jl2 = new JLabel("旅游地点");
String []nation = {"北京","上海","深圳","广州"};
jcb1 = new JComboBox(nation);
String []trival = {"地点1","地点2","地点3","地点4"};
jlist = new JList(trival);
jlist.setVisibleRowCount(2);//设置列表显示的行数
jsp = new JScrollPane(jlist);//设置滚动条
jp1.add(jl1);
jp1.add(jcb1);
jp2.add(jl2);
jp2.add(jsp);
this.setLayout(new GridLayout(2,1));
this.add(jp1);
this.add(jp2);
//设置JFrame属性
this.setTitle("JComboBox,JList");
this.setSize(300,150);
this.setResizable(false);
this.setLocation(300,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
new Demo10();
}
}
JComboBox,JList
最新推荐文章于 2020-10-10 18:11:26 发布