窗体组件JFrame 面板组件JPanel 容器类组件,可以加入其它组件(3)

窗体组件JFrame 面板组件JPanel 容器类组件,可以加入其它组件(3)_第1张图片

//JComboBox/JList/JScrollPane
package com.test;
import java.awt.*;
import javax.swing.*;
public class Demo8_8 extends JFrame{

	JPanel jp1,jp2;
	JLabel jl1,jl2;
	JComboBox jcb1;
	JList jlist;
	JScrollPane jsp;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Demo8_8 demo8_8=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);
		//设置希望显示多少个选项
		//jsp.set
		//设置布局
		this.setLayout(new GridLayout(2,1));
		
		//添加组件
		jp1.add(jl1);
		jp1.add(jcb1);
		
		jp2.add(jl2);
		jp2.add(jsp);
		
		this.add(jp1);
		this.add(jp2);
		this.setSize(300,300);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}

}

  

转载于:https://www.cnblogs.com/Telecom-Latecomer/p/3677105.html

你可能感兴趣的:(窗体组件JFrame 面板组件JPanel 容器类组件,可以加入其它组件(3))