JAVA用JComboBox_java JCombobox和JList的使用

/*

* 功能: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);

}

}

67bbe364fa0a62e6f590b2a913fd15eb.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值