tailieunhanh - lt_java_csdl_bai_3_components_part_2_6359

| LẬP TRÌNH JAVA CSDL BÀI 3 COMPONENTS Nguyễn Hữu Thể 1 Nội dung JList JTable JMenu JOptionPane JFileChooser 2 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 quot fire quot 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 LECTION -1 . JScrollPane listScroller new JScrollPane list new Dimension 250 80 JList DefaultListModel Methods addElement Object e get int index getSize getElementAt int index remove int index Elements removeAllElements 5 JList Methods setModel ListModel model getModel getMaxSelectionIndex getMinSelectionIndex getSelectedIndex getSelectedIndices getSelectedValue getSelectedValues Events valueChanged 6 JTable 7 JOptionPane 8 JTable DefaultTableModel addColumn Object obj addRow Object obj getColumnCount getRowCount getValueAt int row int col setValueAt Object obj int row int col 9 JTable Methods setModel TableModel tm getModel getValueAt int row int col getRowCount getColumnCount Events mouseClicked 10 JTable package project import import import public class JTableComponent public static void main String argv throws Exception Object cellData quot 1-1 quot quot 1-2 quot quot 2-1 quot quot 2-2 quot String columnNames quot col1 quot quot col2 quot JTable table new JTable cellData columnNames JFrame f new JFrame 300 300 new JScrollPane table true 11 JTable DefaultTableModel Constructs a default DefaultTableModel which is

TỪ KHÓA LIÊN QUAN