Use of JList
- JList compared to Jcheckbox, you can select a maximum of one item, and JList can be selected as a whole column .
- The third constructor cannot change the number of items
--Construct a simple list
ImportJava.awt.Container;Importjava.awt.GridLayout;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;ImportJava.util.Vector;Importjavax.swing.BorderFactory;ImportJavax.swing.JFrame;Importjavax.swing.JList;ImportJavax.swing.JScrollPane; Public classJList01 { Public Static voidMain (string[] args) {JFrame F=NewJFrame (); Container ContentPane=F.getcontentpane (); F.setlayout (NewGridLayout (1, 2)); String[] s=Newstring[]{"Japan", "England", "France", "China", "USA"}; Vector v=NewVector (); V.addelement ("Nokia 8850"); V.addelement ("Nokia 8250"); V.addelement ("Notorola v8088"); V.addelement ("Motorola v3688"); V.addelement ("Panasonic GD92"); V.addelement (Other); JList JList=NewJList (s); Jlist.setborder (Borderfactory.createtitledborder ("Which country do you like to play most?")); JList JList2=NewJList (v); Jlist2.setborder (Borderfactory.createtitledborder ("Which phone do you like best?")); Contentpane.add ( New JScrollPane (jList)); Contentpane.add ( New JScrollPane (jList2)); Contentpane.add (JLIST2); F.pack (); F.show (); F.addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosing (windowevent e) {//TODO auto-generated Method StubSystem.exit (0); } }); }}
In this window, when the window becomes small, the list has no scrolling effect, and the red Code snippet can show the effect
* Select mode (Selection modes)
Set selection mode you can use the Setselectionmode method provided by jlist (int selectionmode)
JList use is not more complete