import java.awt.*;
import javax.swing.*;
public class Demo31_3 extends JFrame
{
JPanel jp1,jp2;
JLabel jlb1,jlb2;
JComboBox jcb;
JList jlist;
JScrollPane jsp;
public Demo31_3()
{
jp1=new JPanel();
jp2=new JPanel();
jlb1=new JLabel("你的性别");
jlb2=new JLabel("你出省的日期");
//String []jg={"北京","上海","武汉","陕西","地球"};
String []jg={"男","女"};
jcb=new JComboBox(jg);
String []adress={"2000","2001","2002","2003","2005","2005"};
jlist=new JList(adress);
//设置你希望显示多少个选项
jlist.setVisibleRowCount(3);
jsp=new JScrollPane(jlist);
//设置布局
this.setLayout(new GridLayout(3,1));
//添加组件
jp1.add(jlb1);
jp1.add(jcb);
jp2.add(jlb2);
jp2.add(jsp); //如果是jp2.add(jlist);则不显示滚动条
this.add(jp1);
this.add(jp2);
//设置窗口属性
this.setSize(200,350);
this.setLocation(300,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.setResizable(false);
this.setVisible(true);
}
public static void main(String []args)
{
Demo31_3 de=new Demo31_3();
}
} |