1. /*
  2. * @(#)TableModel.java 1.22 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.table;
  11. import javax.swing.*;
  12. import javax.swing.event.*;
  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.22 02/02/00
  29. * @author Philip Milne
  30. * @see JTable
  31. */
  32. public interface TableModel
  33. {
  34. /**
  35. * Returns the number of rows in the model. A
  36. * <code>JTable</code> uses this method to determine how many rows it
  37. * should display. This method should be quick, as it
  38. * is called frequently during rendering.
  39. *
  40. * @return the number of rows in the model
  41. * @see #getColumnCount
  42. */
  43. public int getRowCount();
  44. /**
  45. * Returns the number of columns in the model. A
  46. * <code>JTable</code> uses this method to determine how many columns it
  47. * should create and display by default.
  48. *
  49. * @return the number of columns in the model
  50. * @see #getRowCount
  51. */
  52. public int getColumnCount();
  53. /**
  54. * Returns the name of the column at <code>columnIndex</code>. This is used
  55. * to initialize the table's column header name. Note: this name does
  56. * not need to be unique; two columns in a table can have the same name.
  57. *
  58. * @param columnIndex the index of the column
  59. * @return the name of the column
  60. */
  61. public String getColumnName(int columnIndex);
  62. /**
  63. * Returns the most specific superclass for all the cell values
  64. * in the column. This is used by the <code>JTable</code> to set up a
  65. * default renderer and editor for the column.
  66. *
  67. * @param columnIndex the index of the column
  68. * @return the common ancestor class of the object values in the model.
  69. */
  70. public Class getColumnClass(int columnIndex);
  71. /**
  72. * Returns true if the cell at <code>rowIndex</code> and
  73. * <code>columnIndex</code>
  74. * is editable. Otherwise, <code>setValueAt</code> on the cell will not
  75. * change the value of that cell.
  76. *
  77. * @param rowIndex the row whose value to be queried
  78. * @param columnIndex the column whose value to be queried
  79. * @return true if the cell is editable
  80. * @see #setValueAt
  81. */
  82. public boolean isCellEditable(int rowIndex, int columnIndex);
  83. /**
  84. * Returns the value for the cell at <code>columnIndex</code> and
  85. * <code>rowIndex</code>.
  86. *
  87. * @param rowIndex the row whose value is to be queried
  88. * @param columnIndex the column whose value is to be queried
  89. * @return the value Object at the specified cell
  90. */
  91. public Object getValueAt(int rowIndex, int columnIndex);
  92. /**
  93. * Sets the value in the cell at <code>columnIndex</code> and
  94. * <code>rowIndex</code> to <code>aValue</code>.
  95. *
  96. * @param aValue the new value
  97. * @param rowIndex the row whose value is to be changed
  98. * @param columnIndex the column whose value is to be changed
  99. * @see #getValueAt
  100. * @see #isCellEditable
  101. */
  102. public void setValueAt(Object aValue, int rowIndex, int columnIndex);
  103. /**
  104. * Adds a listener to the list that is notified each time a change
  105. * to the data model occurs.
  106. *
  107. * @param l the TableModelListener
  108. */
  109. public void addTableModelListener(TableModelListener l);
  110. /**
  111. * Removes a listener from the list that is notified each time a
  112. * change to the data model occurs.
  113. *
  114. * @param l the TableModelListener
  115. */
  116. public void removeTableModelListener(TableModelListener l);
  117. }