Source:
<span style= "FONT-SIZE:18PX;" >import java.util.Vector; import java.awt.GridLayout; import Java.awt.Container; import java.awt.event.WindowAdapter; import java.awt.event.WindowListener; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.BorderFactory; Import Javax.swing.ListSelectionModel; class mylist{JFrame frame = new JFrame (); Container con = Frame.getcontentpane (); Get the form container private JList list1 = null; Private JList list2 = null; Public MyList () {this.frame.setLayout (new GridLayout (1,3)); String brother[] = {"Eldest brother", "", "small three", "small Four", "Small Five", "eldest brother", "Stay moe", "small three", "small Four", "Small Five"}; Vector<string> v = new vector<string> (); V.add ("Spring"); V.add ("Summer"); V.add ("Autumn"); V.add ("Winter"); This.list1 = new JList (brother); This.list2 = new JList (v); This.list1.setBorder (Borderfactory.createtitledborder ("Who Are You?") ")) ;This.list2.setBorder (Borderfactory.createtitledborder ("What season is Now")); This.list1.setSelectionMode (listselectionmodel.multiple_interval_selection); Multi-select This.list2.setSelectionMode (listselectionmodel.single_selection); Radio This.con.add (New JScrollPane (This.list1)); This.con.add (THIS.LIST2); This.frame.setSize (300,300); This.frame.setVisible (TRUE); This.frame.addWindowListener (New Windowadapter () {public void windowclosing (WindowEvent e) { System.exit (1); } }) ; }}class tester{public static void Main (String args[]) {new MyList (); }}</span>
Common monitoring:
<span style= "FONT-SIZE:18PX;" >import java.util.Vector; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; import Java.awt.event.WindowListener; import Javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; import java.awt.Container; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.BorderFactory; Import Javax.swing.AbstractListModel; import Javax.swing.ListSelectionModel; class Mylistmodel extends abstractlistmodel{private String brothers[] = {"Eldest brother", "Stay moe", "small three", "small Four", "Small Five"}; Public Object getelementat (int index) {if (index<brothers.length) return brothers[index]; else return null; } public int GetSize () {return brothers.length; }}class MyList implements listselectionlistener{JFrame frame = new JFrame (); Container con = Frame.getcontentpane (); Private JList list = null; Public MyList () {thiS.frame.setlayout (New GridLayout (1,3)); This.list = new JList (new Mylistmodel ()); This.list.setBorder (Borderfactory.createtitledborder ("Who Are You?") ")) ; This.list.setSelectionMode (listselectionmodel.multiple_interval_selection); This.con.add (new JScrollPane (list)); This.frame.setSize (400,400); This.frame.setVisible (TRUE); This.list.addListSelectionListener (this); This.frame.addWindowListener (New Windowadapter () {public void windowclosing (WindowEvent a) {Syst Em.exit (1); } }) ; } public void ValueChanged (Listselectionevent e) {int temp[] = list.getselectedindices (); int temp[] = list1.getselectedindices (); System.out.println ("The selected content is:"); for (int i=0;i<temp.length;i++) {System.out.println (List.getmodel (). Getelementat (i)); }}}class tester{public static void Main (String args[]) {new MyList (); }}</span>
List box jlist and motion monitoring