標籤:
1 package com.soft.test; 2 3 /** 4 * 下拉式清單、下拉框、捲軸的使用 5 */ 6 7 import javax.swing.*; 8 import java.awt.*; 9 public class Dem5 extends JFrame {10 11 12 private JPanel jp1, jp2;13 private JLabel jlb1, jlb2;14 private JComboBox jb1;15 private JList jl;16 private JScrollPane jsp;17 18 public Dem5() {19 jp1 = new JPanel();20 jp2 = new JPanel();21 jlb1 = new JLabel("籍貫");22 jlb2 = new JLabel("旅遊地點");23 24 25 String []jz = {"南昌","贛州","吉安","新喻","鷹潭","景德鎮","撫州"};26 jb1 = new JComboBox(jz);27 String []ly = {"三清山","將軍園","龍虎山","廬山","騰王閣"};28 29 jl = new JList(ly);30 jsp = new JScrollPane(jl);31 jl.setVisibleRowCount(3);32 33 this.setLayout(new GridLayout(3, 1));34 35 jp1.add(jlb1);36 jp1.add(jb1);37 jp2.add(jlb2);38 jp2.add(jsp);39 this.add(jp1);40 this.add(jp2);41 this.setSize(300,300);42 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);43 this.setLocation(300,300);44 this.setVisible(true);45 this.setResizable(false); 46 }47 48 public static void main(String args[]) {49 50 Dem5 dem5 = new Dem5();51 }52 }
java下拉框,捲軸