KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > table > TableModel


1 /*
2  * @(#)TableModel.java 1.26 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.table;
9
10 import javax.swing.*;
11 import javax.swing.event.*;
12
13 /**
14  * The <code>TableModel</code> interface specifies the methods the
15  * <code>JTable</code> will use to interrogate a tabular data model. <p>
16  *
17  * The <code>JTable</code> can be set up to display any data
18  * model which implements the
19  * <code>TableModel</code> interface with a couple of lines of code: <p>
20  * <pre>
21  * TableModel myData = new MyTableModel();
22  * JTable table = new JTable(myData);
23  * </pre><p>
24  *
25  * For further documentation, see <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data">Creating a Table Model</a>
26  * in <em>The Java Tutorial</em>.
27  * <p>
28  * @version 1.26 05/05/04
29  * @author Philip Milne
30  * @see JTable
31  */

32
33 public interface TableModel
34 {
35     /**
36      * Returns the number of rows in the model. A
37      * <code>JTable</code> uses this method to determine how many rows it
38      * should display. This method should be quick, as it
39      * is called frequently during rendering.
40      *
41      * @return the number of rows in the model
42      * @see #getColumnCount
43      */

44     public int getRowCount();
45
46     /**
47      * Returns the number of columns in the model. A
48      * <code>JTable</code> uses this method to determine how many columns it
49      * should create and display by default.
50      *
51      * @return the number of columns in the model
52      * @see #getRowCount
53      */

54     public int getColumnCount();
55
56     /**
57      * Returns the name of the column at <code>columnIndex</code>. This is used
58      * to initialize the table's column header name. Note: this name does
59      * not need to be unique; two columns in a table can have the same name.
60      *
61      * @param columnIndex the index of the column
62      * @return the name of the column
63      */

64     public String JavaDoc getColumnName(int columnIndex);
65
66     /**
67      * Returns the most specific superclass for all the cell values
68      * in the column. This is used by the <code>JTable</code> to set up a
69      * default renderer and editor for the column.
70      *
71      * @param columnIndex the index of the column
72      * @return the common ancestor class of the object values in the model.
73      */

74     public Class JavaDoc<?> getColumnClass(int columnIndex);
75
76     /**
77      * Returns true if the cell at <code>rowIndex</code> and
78      * <code>columnIndex</code>
79      * is editable. Otherwise, <code>setValueAt</code> on the cell will not
80      * change the value of that cell.
81      *
82      * @param rowIndex the row whose value to be queried
83      * @param columnIndex the column whose value to be queried
84      * @return true if the cell is editable
85      * @see #setValueAt
86      */

87     public boolean isCellEditable(int rowIndex, int columnIndex);
88
89     /**
90      * Returns the value for the cell at <code>columnIndex</code> and
91      * <code>rowIndex</code>.
92      *
93      * @param rowIndex the row whose value is to be queried
94      * @param columnIndex the column whose value is to be queried
95      * @return the value Object at the specified cell
96      */

97     public Object JavaDoc getValueAt(int rowIndex, int columnIndex);
98
99     /**
100      * Sets the value in the cell at <code>columnIndex</code> and
101      * <code>rowIndex</code> to <code>aValue</code>.
102      *
103      * @param aValue the new value
104      * @param rowIndex the row whose value is to be changed
105      * @param columnIndex the column whose value is to be changed
106      * @see #getValueAt
107      * @see #isCellEditable
108      */

109     public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex);
110
111     /**
112      * Adds a listener to the list that is notified each time a change
113      * to the data model occurs.
114      *
115      * @param l the TableModelListener
116      */

117     public void addTableModelListener(TableModelListener l);
118
119     /**
120      * Removes a listener from the list that is notified each time a
121      * change to the data model occurs.
122      *
123      * @param l the TableModelListener
124      */

125     public void removeTableModelListener(TableModelListener l);
126 }
127
128
Popular Tags