/*
* 功能:JComboBox,JList,JScrollPane
*
*/
package com.haitao.gui;
import javax.swing.*;
import java.awt.*;
public class Demo8_8 extends JFrame {
//定义
JPanel jp1,jp2;
JLabel jl1,jl2;
JComboBox jcb1;
JList jlist;
JScrollPane jsp;
public static void main(String[] args) {
Demo8_8 demo=new Demo8_8();
}
//构造函数
public Demo8_8()
{
jp1=new JPanel();
jp2=new JPanel();
jl1=new JLabel("你的籍贯");
jl2=new JLabel("旅游地点");
String []jg={"北京","上海","天津","火星"};
jcb1=new JComboBox(jg);
String []dd={"九寨沟","故宫","长城","天安门"};
jlist=new JList(dd);
//设置你希望显示多少个选项
jlist.setVisibleRowCount(2);
jsp=new JScrollPane(jlist);
//设置布局
this.setLayout(new GridLayout(3,1));
//添加组件
jp1.add(jl1 );
jp1.add(jcb1);
jp2.add(jl2);
jp2.add(jsp);
this.add(jp1);
this.add(jp2);
this.setSize(300,300);
this.setLocation(20,20);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
java 中 JComboBox,JList,JScrollPane的用法
最新推荐文章于 2023-12-29 03:53:57 发布