//Drop- down lists and scroll barsImportjava.awt.*;Importjavax.swing.*; Public classJiemian7extendsjframe{JPanel MB1,MB2; //Panel DefinitionJLabel bq1,bq2;//Label DefinitionJComboBox xlk;//Drop- down boxJList lb;//radio button DefinitionJScrollPane GD;//scroll bar Public Static voidMain (string[] args) {//to run this class of construction methodsJiemian7 Jiemian =NewJiemian7 (); } PublicJiemian7 () {//Create a panelMB1 =NewJPanel (); MB2=NewJPanel (); BQ1=NewJLabel ("Hometown"); BQ2=NewJLabel ("Education"); String[] JG= {"Beijing", "Tianjin", "Shanghai", "Chongqing"}; Xlk=NewJComboBox (JG); String[] XL= {"High school", "College", "undergraduate", "Master", "PhD"}; LB=NewJList (XL); Lb.setvisiblerowcount (3);//How many rows are scrolledGd=NewJScrollPane (LB);//Unlike radio buttons, here you add a scroll component to the Panel//Use grid layout This. setlayout (NewGridLayout (2,1)); //Add a button to a panelMb1.add (BQ1); Mb1.add (XLK); Mb2.add (BQ2); Mb2.add (GD); //Add a panel to the interface This. Add (MB1); This. Add (MB2); //Set Window caption This. Settitle ("drop-down list and scroll bar"); //Set the width height of the window This. SetSize (300,150); //The Settings window appears for the location of the screen This. setlocation (100,100); //no pulling the big pull small This. setresizable (false); //releasing a resource after closing a window This. Setdefaultcloseoperation (Jframe.exit_on_close); //Output Window This. setvisible (true); } }
JAVA drop-down list and scroll bar