1
LẬP TRÌNH JAVA CSDL
BÀI 3
COMPONENTS
Nguyễn Hữu Thể
2
Nội dung
JList
JTable
JMenu
JOptionPane
JFileChooser
JList
Creating a Model
There are three ways to create a list model:
DefaultListModel everything is pretty much taken care of for you.
The examples in this page use DefaultListModel.
AbstractListModel you manage the data and invoke the "fire"
methods. For this approach, you must subclass AbstractListModel and
implement the getSize and getElementAt methods inherited from the
ListModel interface.
ListModel you manage everything.
JList
Initializing a List
list = new JList(data); //data has type Object[]
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SE
LECTION);
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(-1);
...
JScrollPane listScroller = new JScrollPane(list);
listScroller.setPreferredSize(new Dimension(250, 80));
JList
DefaultListModel
Methods:
• addElement (Object e)
• get (int index)
• getSize ()
• getElementAt (int index)
• remove (int index)
• Elements()
• removeAllElements ()
5