下拉選單框和滾動條

託帕發表於2018-09-07

import java.awt.*;
import javax.swing.*;

public class Test extends JFrame{//把需要的元件全部在這裡定義
	
	JPanel mb1,mb2;
	JLabel bq1,bq2;
	JComboBox xlk;
	JList lb;
	JScrollPane gd;
	
	
	public static void main(String[] args){
		Test lx=new Test();
	}

public Test(){
	
	    mb1=new JPanel();
	    mb2=new JPanel();
	     
		bq1=new JLabel("籍貫");
		bq2=new JLabel("學歷");
		
		String[] jg={"北京","新增","上海","重慶"};
		xlk=new JComboBox(jg);
		
		String[] xl={"高中","大專","本科","碩士","博士"};
		lb=new JList(xl);
		
		lb.setVisibleRowCount(3);
		gd=new JScrollPane(lb);
				
		this.setLayout(new GridLayout(2,1));
		
		mb1.add(bq1);mb1.add(xlk);
		mb2.add(bq2);mb2.add(gd);
		
		this.add(mb1);
		this.add(mb2);
				
		this.setTitle("使用者調查");
		this.setSize(350,300);
		this.setLocation(400,280);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
}

相關文章