Drop-down box (JComboBox) list box (JList) scrolling window (jscrollpane) package gui;import java.awt.gridlayout;import javax.swing.*; /*** dropdown box, list box, window scroll * Created by admin on 2017/7/9.*/public class Scroll extends jframe{//define required components private JList Jlist;priva Te JComboBox jcombobox;private jscrollpane jscrollpane;private JLabel JLabel, jlabel2;private JPanel JPanel, JPanel2; public static void Main (string[] args) {Scroll Scroll = new Scroll ();} Public Scroll () {jPanel = new JPanel (); jPanel2 = new JPanel (); JLabel = new JLabel ("province"); JLabel2 = new JLabel ("City"); String [] province = {"Guangxi", "Guangdong", "Hunan"};//dropdown box JComboBox = new JComboBox (province); String [] City = {"Nanning", "Liuzhou", "Guangzhou", "Shenzhen", "Changsha"};//list box JList = new JList (city); Jlist.setvisiblerowcount (3);//Window scrolling Jscrollpan E = new JScrollPane (jList), This.setlayout (New GridLayout (2, 1)); Jpanel.add (JLabel); Jpanel.add (JComboBox); Jpanel2.add (JLABEL2); Jpanel2.add (JScrollPane); this.add (JPanel); This.add (JPanel2); This.settitle ("Java"); This.setlocation (this.setsize);This.setdefaultcloseoperation (Jframe.exit_on_close); this.setvisible (True);}}
Java GUI programming (swing) four swing drop-down box, list box, scrolling window