Bài giảng "Lập trình Java - Graphic user interface in Java" trình bày các nội dung: JList, JTable, JTree, JSplitPane, Jslider, MDI - multiple document interface. nội dung chi tiết. | 1/3/2016 05. Graphic User Interface in Java Faculty of Information Technologies Industrial University of Ho Chi Minh City 1 GUI components (p4) JList JTable JTree JSplitPane Jslider MDI - multiple document interface 2 JList • Purpose o • To present a list of items from which the user can choose Behavior o Items in JList can be selected individually or in a group o A JList does not provide support for double-click action 3 1 1/3/2016 JList – Constructors • JList() o • Constructs a JList with an empty model JList( Object[] listData ) o Displays the elements of the specified array o Example: String[] words= { "quick", "brown", "hungry", "wild", . }; JList wordList = new JList(words); • JList ( ListModel dataModel ) o Displays the elements in the specified, non-null list model 4 JList – Methods • • int getSelectedIndex() void setSelectedIndex(int index) o • o • returns the selected values or an empty array if the selection is empty boolean isSelectedIndex(int index) o • returns the first selected value or null if the selection is empty Object[] getSelectedValues() o • gets or sets the selected index Object getSelectedValue() returns true if the specified index is selected boolean isSelectionEmpty() o returns true if no item is currently selected 5 JList – Methods (contd.) • • int getVisibleRowCount() void setVisibleRowCount( int height ) o get or set the number of rows in the list that can be displayed without a scroll bar • • int getSelectionMode() void setSelectionMode( int mode ) o , , , by default, a user can select multiple items 6 2 1/3/2016 Handle event of JList • When the current selection changes, JList object generates a ListSelection event o Method: public void valueChanged (ListSelectionEvent e) { Object value = (); //do something with .