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. package javax.swing.table;
  8. import javax.swing.*;
  9. import javax.swing.event.*;
  10. /**
  11. * The <code>TableModel</code> interface specifies the methods the
  12. * <code>JTable</code> will use to interrogate a tabular data model. <p>
  13. *
  14. * The <code>JTable</code> can be set up to display any data
  15. * model which implements the
  16. * <code>TableModel</code> interface with a couple of lines of code: <p>
  17. * <pre>
  18. * TableModel myData = new MyTableModel();
  19. * JTable table = new JTable(myData);
  20. * </pre><p>
  21. *
  22. * For further documentation, see <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#data">Creating a Table Model</a>
  23. * in <em>The Java Tutorial</em>.
  24. * <p>
  25. * @version 1.26 05/05/04
  26. * @author Philip Milne
  27. * @see JTable
  28. */
  29. public interface TableModel
  30. {
  31. /**
  32. * Returns the number of rows in the model. A
  33. * <code>JTable</code> uses this method to determine how many rows it
  34. * should display. This method should be quick, as it
  35. * is called frequently during rendering.
  36. *
  37. * @return the number of rows in the model
  38. * @see #getColumnCount
  39. */
  40. public int getRowCount();
  41. /**
  42. * Returns the number of columns in the model. A
  43. * <code>JTable</code> uses this method to determine how many columns it
  44. * should create and display by default.
  45. *
  46. * @return the number of columns in the model
  47. * @see #getRowCount
  48. */
  49. public int getColumnCount();
  50. /**
  51. * Returns the name of the column at <code>columnIndex</code>. This is used
  52. * to initialize the table's column header name. Note: this name does
  53. * not need to be unique; two columns in a table can have the same name.
  54. *
  55. * @param columnIndex the index of the column
  56. * @return the name of the column
  57. */
  58. public String getColumnName(int columnIndex);
  59. /**
  60. * Returns the most specific superclass for all the cell values
  61. * in the column. This is used by the <code>JTable</code> to set up a
  62. * default renderer and editor for the column.
  63. *
  64. * @param columnIndex the index of the column
  65. * @return the common ancestor class of the object values in the model.
  66. */
  67. public Class<?> getColumnClass(int columnIndex);
  68. /**
  69. * Returns true if the cell at <code>rowIndex</code> and
  70. * <code>columnIndex</code>
  71. * is editable. Otherwise, <code>setValueAt</code> on the cell will not
  72. * change the value of that cell.
  73. *
  74. * @param rowIndex the row whose value to be queried
  75. * @param columnIndex the column whose value to be queried
  76. * @return true if the cell is editable
  77. * @see #setValueAt
  78. */
  79. public boolean isCellEditable(int rowIndex, int columnIndex);
  80. /**
  81. * Returns the value for the cell at <code>columnIndex</code> and
  82. * <code>rowIndex</code>.
  83. *
  84. * @param rowIndex the row whose value is to be queried
  85. * @param columnIndex the column whose value is to be queried
  86. * @return the value Object at the specified cell
  87. */
  88. public Object getValueAt(int rowIndex, int columnIndex);
  89. /**
  90. * Sets the value in the cell at <code>columnIndex</code> and
  91. * <code>rowIndex</code> to <code>aValue</code>.
  92. *
  93. * @param aValue the new value
  94. * @param rowIndex the row whose value is to be changed
  95. * @param columnIndex the column whose value is to be changed
  96. * @see #getValueAt
  97. * @see #isCellEditable
  98. */
  99. public void setValueAt(Object aValue, int rowIndex, int columnIndex);
  100. /**
  101. * Adds a listener to the list that is notified each time a change
  102. * to the data model occurs.
  103. *
  104. * @param l the TableModelListener
  105. */
  106. public void addTableModelListener(TableModelListener l);
  107. /**
  108. * Removes a listener from the list that is notified each time a
  109. * change to the data model occurs.
  110. *
  111. * @param l the TableModelListener
  112. */
  113. public void removeTableModelListener(TableModelListener l);
  114. }