Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click here for Oracle 8i Internet Seminars.
Click here for Oracle 8i Internet Seminars.
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


The TableColumnModel Interface and Associated Classes

The JTable class delegates column information to a column model. The required methods for a column model class are defined in the TableColumnModel interface shown in Listing 12.4. The TableColumnModel interface is another long interface that typically will not be implemented by developers. The DefaultTableColumnModel class is provided for use in JTable instances. However, the flexibility to replace the DefaultTableColumnModel is available, if required, as long as the replacement column model class implements this interface. This is a good design pattern for Java development. The view class interfaces to model classes through interfaces, and a default implementation of that class is provided. This allows for the view to be easily used with default behavior and still allow that behavior to be overridden or extended by providing custom classes that implement the model interface.

Listing 12.4 The TableColumnModel Interface

public interface TableColumnModel
{
//
// Modifying the model
//

    /**
     * Appends <I>aColumn</I> to the end of the receiver’s tableColumns
     * array. This method also posts the columnAdded() event to its
     * listeners.
     *
     * @param   aColumn         The <B>TableColumn</B> to be added
     * @see     #removeColumn()
     */
    public void addColumn(TableColumn aColumn);

    /**
     * Deletes the <B>TableColumn</B> <I>column</I> from the
     * receiver’s table column’s array.  This method will do nothing if
     * <I>column</I> is not in the table’s column’s list.
     * This method also posts the columnRemoved() event to its
     * listeners.
     *
     * @param   column          The <B>TableColumn</B> to be removed
     * @see     #addColumn()
     */
    public void removeColumn(TableColumn column);

    /**
     * Moves the column and heading at <I>columnIndex</I> to
     * <I>newIndex</I>. The old column at <I>columnIndex</I> will now be
     * found at <I>newIndex</I>. The column that used to be at
     * <I>newIndex</I> is shifted left or right to make room.
     * This will not move any columns if <I>columnIndex</I> equals
     * <I>newIndex</I>. This method also posts the columnMoved()
     * event to its listeners.
     *
     * @param columnIndex the index of column to be moved
     * @param newIndex New index to move the column
     * @exception IllegalArgumentException if <I>column</I> or
     *                                     <I>newIndex</I>
     *                                     are not in the valid range
     */
    public void moveColumn(int columnIndex, int newIndex);

    /**
     * Sets the <B>TableColumn’s</B> column margin to <I>newMargin</I>.
     * This method also posts the columnMarginChanged() event to its
     * listeners.
     *
     * @param   newMargin               the width margin of the column
     * @see     #getColumnMargin()
     */
    public void setColumnMargin(int newMargin);

//
// Querying the model
//

    /** Returns the number of columns in the model */
    public int getColumnCount();

    /** Returns an Enumeration of all the columns in the model */
    public Enumeration getColumns();

    /**
     * Returns the index of the first column in the receiver’s
     * column’s array whose identifier is equal to <I>identifier</I>,
     * when compared using <I>equals()</I>.
     *
     * @return the index of the first table column in the receiver’s
     *         tableColumns array whose identifier is equal to
     *         <I>identifier</I>, when compared using equals().
     * @param  identifier  the identifier object
     * @exception IllegalArgumentException if <I>identifier</I>
     *            is null or no TableColumn has this identifier
     * @see #getColumn()
     */
    public int getColumnIndex(Object columnIdentifier);

    /**
     * Returns the <B>TableColumn</B> object for the column at
     * <I>columnIndex</I>
     *
     * @return the TableColumn object for the column at
     *         <I>columnIndex</I>
     * @param  columnIndex     the index of the column desired
     */
    public TableColumn getColumn(int columnIndex);

    /** Returns the width margin between each column */
    public int getColumnMargin();

    /**
     * Returns the index of the column that lies on the <I>xPosition</I>,
     * or -1 if it lies outside the any of the column’s bounds.
     *
     * @return  the index of the column or -1 if no column is found
     */
    public int getColumnIndexAtX(int xPosition);
    /** Returns the total width of all the columns. */
    public int getTotalColumnWidth();

//
// Selection
//

    /**
     * Sets whether the columns in this model can be selected.
     * @see #getColumnSelectionAllowed()
     */
    public void setColumnSelectionAllowed(boolean flag);

    /**
     * @return true if columns can be selected.
     * @see #setColumnSelectionAllowed()
     */
    public boolean getColumnSelectionAllowed();

    /**
     * @return the indices of all selected columns, or an empty int array
     *         if no column is selected.
     */
    public int[] getSelectedColumns();

    /**
     * @return the number of selected columns.  0 if no columns are
     *         selected.
     */
    public int getSelectedColumnCount();

    public void setSelectionModel(ListSelectionModel newModel);

    public ListSelectionModel getSelectionModel();

//
// Listener
//

    public void addColumnModelListener(TableColumnModelListener x);
    public void removeColumnModelListener(TableColumnModelListener x);
}


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.