0N/A/*
2362N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing.table;
0N/A
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.event.SwingPropertyChangeSupport;
0N/Aimport java.lang.Integer;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Component;
0N/Aimport java.io.Serializable;
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.beans.PropertyChangeListener;
0N/A
0N/A/**
0N/A * A <code>TableColumn</code> represents all the attributes of a column in a
0N/A * <code>JTable</code>, such as width, resizibility, minimum and maximum width.
0N/A * In addition, the <code>TableColumn</code> provides slots for a renderer and
0N/A * an editor that can be used to display and edit the values in this column.
0N/A * <p>
0N/A * It is also possible to specify renderers and editors on a per type basis
0N/A * rather than a per column basis - see the
0N/A * <code>setDefaultRenderer</code> method in the <code>JTable</code> class.
0N/A * This default mechanism is only used when the renderer (or
0N/A * editor) in the <code>TableColumn</code> is <code>null</code>.
0N/A * <p>
0N/A * The <code>TableColumn</code> stores the link between the columns in the
0N/A * <code>JTable</code> and the columns in the <code>TableModel</code>.
0N/A * The <code>modelIndex</code> is the column in the
0N/A * <code>TableModel</code>, which will be queried for the data values for the
0N/A * cells in this column. As the column moves around in the view this
0N/A * <code>modelIndex</code> does not change.
0N/A * <p>
0N/A * <b>Note:</b> Some implementations may assume that all
0N/A * <code>TableColumnModel</code>s are unique, therefore we would
0N/A * recommend that the same <code>TableColumn</code> instance
0N/A * not be added more than once to a <code>TableColumnModel</code>.
0N/A * To show <code>TableColumn</code>s with the same column of
0N/A * data from the model, create a new instance with the same
0N/A * <code>modelIndex</code>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @author Alan Chung
0N/A * @author Philip Milne
0N/A * @see javax.swing.table.TableColumnModel
0N/A *
0N/A * @see javax.swing.table.DefaultTableColumnModel
0N/A * @see javax.swing.table.JTableHeader#getDefaultRenderer()
0N/A * @see JTable#getDefaultRenderer(Class)
0N/A * @see JTable#getDefaultEditor(Class)
0N/A * @see JTable#getCellRenderer(int, int)
0N/A * @see JTable#getCellEditor(int, int)
0N/A */
0N/Apublic class TableColumn extends Object implements Serializable {
0N/A
0N/A /**
0N/A * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
0N/A * properties.
0N/A */
0N/A /*
0N/A * Warning: The value of this constant, "columWidth" is wrong as the
0N/A * name of the property is "columnWidth".
0N/A */
0N/A public final static String COLUMN_WIDTH_PROPERTY = "columWidth";
0N/A
0N/A /**
0N/A * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
0N/A * properties.
0N/A */
0N/A public final static String HEADER_VALUE_PROPERTY = "headerValue";
0N/A
0N/A /**
0N/A * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
0N/A * properties.
0N/A */
0N/A public final static String HEADER_RENDERER_PROPERTY = "headerRenderer";
0N/A
0N/A /**
0N/A * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
0N/A * properties.
0N/A */
0N/A public final static String CELL_RENDERER_PROPERTY = "cellRenderer";
0N/A
0N/A//
0N/A// Instance Variables
0N/A//
0N/A
0N/A /**
0N/A * The index of the column in the model which is to be displayed by
0N/A * this <code>TableColumn</code>. As columns are moved around in the
0N/A * view <code>modelIndex</code> remains constant.
0N/A */
0N/A protected int modelIndex;
0N/A
0N/A /**
0N/A * This object is not used internally by the drawing machinery of
0N/A * the <code>JTable</code>; identifiers may be set in the
0N/A * <code>TableColumn</code> as as an
0N/A * optional way to tag and locate table columns. The table package does
0N/A * not modify or invoke any methods in these identifier objects other
0N/A * than the <code>equals</code> method which is used in the
0N/A * <code>getColumnIndex()</code> method in the
0N/A * <code>DefaultTableColumnModel</code>.
0N/A */
0N/A protected Object identifier;
0N/A
0N/A /** The width of the column. */
0N/A protected int width;
0N/A
0N/A /** The minimum width of the column. */
0N/A protected int minWidth;
0N/A
0N/A /** The preferred width of the column. */
0N/A private int preferredWidth;
0N/A
0N/A /** The maximum width of the column. */
0N/A protected int maxWidth;
0N/A
0N/A /** The renderer used to draw the header of the column. */
0N/A protected TableCellRenderer headerRenderer;
0N/A
0N/A /** The header value of the column. */
0N/A protected Object headerValue;
0N/A
0N/A /** The renderer used to draw the data cells of the column. */
0N/A protected TableCellRenderer cellRenderer;
0N/A
0N/A /** The editor used to edit the data cells of the column. */
0N/A protected TableCellEditor cellEditor;
0N/A
0N/A /** If true, the user is allowed to resize the column; the default is true. */
0N/A protected boolean isResizable;
0N/A
0N/A /**
0N/A * This field was not used in previous releases and there are
0N/A * currently no plans to support it in the future.
0N/A *
0N/A * @deprecated as of Java 2 platform v1.3
0N/A */
0N/A /*
0N/A * Counter used to disable posting of resizing notifications until the
0N/A * end of the resize.
0N/A */
0N/A @Deprecated
0N/A transient protected int resizedPostingDisableCount;
0N/A
0N/A /**
0N/A * If any <code>PropertyChangeListeners</code> have been registered, the
0N/A * <code>changeSupport</code> field describes them.
0N/A */
0N/A private SwingPropertyChangeSupport changeSupport;
0N/A
0N/A//
0N/A// Constructors
0N/A//
0N/A
0N/A /**
0N/A * Cover method, using a default model index of 0,
0N/A * default width of 75, a <code>null</code> renderer and a
0N/A * <code>null</code> editor.
0N/A * This method is intended for serialization.
0N/A * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
0N/A */
0N/A public TableColumn() {
0N/A this(0);
0N/A }
0N/A
0N/A /**
0N/A * Cover method, using a default width of 75, a <code>null</code>
0N/A * renderer and a <code>null</code> editor.
0N/A * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
0N/A */
0N/A public TableColumn(int modelIndex) {
0N/A this(modelIndex, 75, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Cover method, using a <code>null</code> renderer and a
0N/A * <code>null</code> editor.
0N/A * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
0N/A */
0N/A public TableColumn(int modelIndex, int width) {
0N/A this(modelIndex, width, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates and initializes an instance of
0N/A * <code>TableColumn</code> with the specified model index,
0N/A * width, cell renderer, and cell editor;
0N/A * all <code>TableColumn</code> constructors delegate to this one.
0N/A * The value of <code>width</code> is used
0N/A * for both the initial and preferred width;
0N/A * if <code>width</code> is negative,
0N/A * they're set to 0.
0N/A * The minimum width is set to 15 unless the initial width is less,
0N/A * in which case the minimum width is set to
0N/A * the initial width.
0N/A *
0N/A * <p>
0N/A * When the <code>cellRenderer</code>
0N/A * or <code>cellEditor</code> parameter is <code>null</code>,
0N/A * a default value provided by the <code>JTable</code>
0N/A * <code>getDefaultRenderer</code>
0N/A * or <code>getDefaultEditor</code> method, respectively,
0N/A * is used to
0N/A * provide defaults based on the type of the data in this column.
0N/A * This column-centric rendering strategy can be circumvented by overriding
0N/A * the <code>getCellRenderer</code> methods in <code>JTable</code>.
0N/A *
0N/A * @param modelIndex the index of the column
0N/A * in the model that supplies the data for this column in the table;
0N/A * the model index remains the same
0N/A * even when columns are reordered in the view
0N/A * @param width this column's preferred width and initial width
0N/A * @param cellRenderer the object used to render values in this column
0N/A * @param cellEditor the object used to edit values in this column
0N/A * @see #getMinWidth()
0N/A * @see JTable#getDefaultRenderer(Class)
0N/A * @see JTable#getDefaultEditor(Class)
0N/A * @see JTable#getCellRenderer(int, int)
0N/A * @see JTable#getCellEditor(int, int)
0N/A */
0N/A public TableColumn(int modelIndex, int width,
0N/A TableCellRenderer cellRenderer,
0N/A TableCellEditor cellEditor) {
0N/A super();
0N/A this.modelIndex = modelIndex;
0N/A preferredWidth = this.width = Math.max(width, 0);
0N/A
0N/A this.cellRenderer = cellRenderer;
0N/A this.cellEditor = cellEditor;
0N/A
0N/A // Set other instance variables to default values.
0N/A minWidth = Math.min(15, this.width);
0N/A maxWidth = Integer.MAX_VALUE;
0N/A isResizable = true;
0N/A resizedPostingDisableCount = 0;
0N/A headerValue = null;
0N/A }
0N/A
0N/A//
0N/A// Modifying and Querying attributes
0N/A//
0N/A
0N/A private void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
0N/A if (changeSupport != null) {
0N/A changeSupport.firePropertyChange(propertyName, oldValue, newValue);
0N/A }
0N/A }
0N/A
0N/A private void firePropertyChange(String propertyName, int oldValue, int newValue) {
0N/A if (oldValue != newValue) {
215N/A firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
0N/A }
0N/A }
0N/A
0N/A private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
0N/A if (oldValue != newValue) {
0N/A firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the model index for this column. The model index is the
0N/A * index of the column in the model that will be displayed by this
0N/A * <code>TableColumn</code>. As the <code>TableColumn</code>
0N/A * is moved around in the view the model index remains constant.
0N/A * @param modelIndex the new modelIndex
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The model index.
0N/A */
0N/A public void setModelIndex(int modelIndex) {
0N/A int old = this.modelIndex;
0N/A this.modelIndex = modelIndex;
0N/A firePropertyChange("modelIndex", old, modelIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns the model index for this column.
0N/A * @return the <code>modelIndex</code> property
0N/A */
0N/A public int getModelIndex() {
0N/A return modelIndex;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>TableColumn</code>'s identifier to
0N/A * <code>anIdentifier</code>. <p>
0N/A * Note: identifiers are not used by the <code>JTable</code>,
0N/A * they are purely a
0N/A * convenience for the external tagging and location of columns.
0N/A *
0N/A * @param identifier an identifier for this column
0N/A * @see #getIdentifier
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: A unique identifier for this column.
0N/A */
0N/A public void setIdentifier(Object identifier) {
0N/A Object old = this.identifier;
0N/A this.identifier = identifier;
0N/A firePropertyChange("identifier", old, identifier);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the <code>identifier</code> object for this column.
0N/A * Note identifiers are not used by <code>JTable</code>,
0N/A * they are purely a convenience for external use.
0N/A * If the <code>identifier</code> is <code>null</code>,
0N/A * <code>getIdentifier()</code> returns <code>getHeaderValue</code>
0N/A * as a default.
0N/A *
0N/A * @return the <code>identifier</code> property
0N/A * @see #setIdentifier
0N/A */
0N/A public Object getIdentifier() {
0N/A return (identifier != null) ? identifier : getHeaderValue();
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>Object</code> whose string representation will be
0N/A * used as the value for the <code>headerRenderer</code>. When the
0N/A * <code>TableColumn</code> is created, the default <code>headerValue</code>
0N/A * is <code>null</code>.
0N/A * @param headerValue the new headerValue
0N/A * @see #getHeaderValue
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The text to be used by the header renderer.
0N/A */
0N/A public void setHeaderValue(Object headerValue) {
0N/A Object old = this.headerValue;
0N/A this.headerValue = headerValue;
0N/A firePropertyChange("headerValue", old, headerValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Object</code> used as the value for the header
0N/A * renderer.
0N/A *
0N/A * @return the <code>headerValue</code> property
0N/A * @see #setHeaderValue
0N/A */
0N/A public Object getHeaderValue() {
0N/A return headerValue;
0N/A }
0N/A
0N/A //
0N/A // Renderers and Editors
0N/A //
0N/A
0N/A /**
0N/A * Sets the <code>TableCellRenderer</code> used to draw the
0N/A * <code>TableColumn</code>'s header to <code>headerRenderer</code>.
0N/A * <p>
0N/A * It is the header renderers responsibility to render the sorting
0N/A * indicator. If you are using sorting and specify a renderer your
0N/A * renderer must render the sorting indication.
0N/A *
0N/A * @param headerRenderer the new headerRenderer
0N/A *
0N/A * @see #getHeaderRenderer
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The header renderer.
0N/A */
0N/A public void setHeaderRenderer(TableCellRenderer headerRenderer) {
0N/A TableCellRenderer old = this.headerRenderer;
0N/A this.headerRenderer = headerRenderer;
0N/A firePropertyChange("headerRenderer", old, headerRenderer);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>TableCellRenderer</code> used to draw the header of the
0N/A * <code>TableColumn</code>. When the <code>headerRenderer</code> is
0N/A * <code>null</code>, the <code>JTableHeader</code>
0N/A * uses its <code>defaultRenderer</code>. The default value for a
0N/A * <code>headerRenderer</code> is <code>null</code>.
0N/A *
0N/A * @return the <code>headerRenderer</code> property
0N/A * @see #setHeaderRenderer
0N/A * @see #setHeaderValue
0N/A * @see javax.swing.table.JTableHeader#getDefaultRenderer()
0N/A */
0N/A public TableCellRenderer getHeaderRenderer() {
0N/A return headerRenderer;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>TableCellRenderer</code> used by <code>JTable</code>
0N/A * to draw individual values for this column.
0N/A *
0N/A * @param cellRenderer the new cellRenderer
0N/A * @see #getCellRenderer
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The renderer to use for cell values.
0N/A */
0N/A public void setCellRenderer(TableCellRenderer cellRenderer) {
0N/A TableCellRenderer old = this.cellRenderer;
0N/A this.cellRenderer = cellRenderer;
0N/A firePropertyChange("cellRenderer", old, cellRenderer);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>TableCellRenderer</code> used by the
0N/A * <code>JTable</code> to draw
0N/A * values for this column. The <code>cellRenderer</code> of the column
0N/A * not only controls the visual look for the column, but is also used to
0N/A * interpret the value object supplied by the <code>TableModel</code>.
0N/A * When the <code>cellRenderer</code> is <code>null</code>,
0N/A * the <code>JTable</code> uses a default renderer based on the
0N/A * class of the cells in that column. The default value for a
0N/A * <code>cellRenderer</code> is <code>null</code>.
0N/A *
0N/A * @return the <code>cellRenderer</code> property
0N/A * @see #setCellRenderer
0N/A * @see JTable#setDefaultRenderer
0N/A */
0N/A public TableCellRenderer getCellRenderer() {
0N/A return cellRenderer;
0N/A }
0N/A
0N/A /**
0N/A * Sets the editor to used by when a cell in this column is edited.
0N/A *
0N/A * @param cellEditor the new cellEditor
0N/A * @see #getCellEditor
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The editor to use for cell values.
0N/A */
0N/A public void setCellEditor(TableCellEditor cellEditor){
0N/A TableCellEditor old = this.cellEditor;
0N/A this.cellEditor = cellEditor;
0N/A firePropertyChange("cellEditor", old, cellEditor);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>TableCellEditor</code> used by the
0N/A * <code>JTable</code> to edit values for this column. When the
0N/A * <code>cellEditor</code> is <code>null</code>, the <code>JTable</code>
0N/A * uses a default editor based on the
0N/A * class of the cells in that column. The default value for a
0N/A * <code>cellEditor</code> is <code>null</code>.
0N/A *
0N/A * @return the <code>cellEditor</code> property
0N/A * @see #setCellEditor
0N/A * @see JTable#setDefaultEditor
0N/A */
0N/A public TableCellEditor getCellEditor() {
0N/A return cellEditor;
0N/A }
0N/A
0N/A /**
0N/A * This method should not be used to set the widths of columns in the
0N/A * <code>JTable</code>, use <code>setPreferredWidth</code> instead.
0N/A * Like a layout manager in the
0N/A * AWT, the <code>JTable</code> adjusts a column's width automatically
0N/A * whenever the
0N/A * table itself changes size, or a column's preferred width is changed.
0N/A * Setting widths programmatically therefore has no long term effect.
0N/A * <p>
0N/A * This method sets this column's width to <code>width</code>.
0N/A * If <code>width</code> exceeds the minimum or maximum width,
0N/A * it is adjusted to the appropriate limiting value.
0N/A * @param width the new width
0N/A * @see #getWidth
0N/A * @see #setMinWidth
0N/A * @see #setMaxWidth
0N/A * @see #setPreferredWidth
0N/A * @see JTable#doLayout()
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The width of the column.
0N/A */
0N/A public void setWidth(int width) {
0N/A int old = this.width;
0N/A this.width = Math.min(Math.max(width, minWidth), maxWidth);
0N/A firePropertyChange("width", old, this.width);
0N/A }
0N/A
0N/A /**
0N/A * Returns the width of the <code>TableColumn</code>. The default width is
0N/A * 75.
0N/A *
0N/A * @return the <code>width</code> property
0N/A * @see #setWidth
0N/A */
0N/A public int getWidth() {
0N/A return width;
0N/A }
0N/A
0N/A /**
0N/A * Sets this column's preferred width to <code>preferredWidth</code>.
0N/A * If <code>preferredWidth</code> exceeds the minimum or maximum width,
0N/A * it is adjusted to the appropriate limiting value.
0N/A * <p>
0N/A * For details on how the widths of columns in the <code>JTable</code>
0N/A * (and <code>JTableHeader</code>) are calculated from the
0N/A * <code>preferredWidth</code>,
0N/A * see the <code>doLayout</code> method in <code>JTable</code>.
0N/A *
0N/A * @param preferredWidth the new preferred width
0N/A * @see #getPreferredWidth
0N/A * @see JTable#doLayout()
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The preferred width of the column.
0N/A */
0N/A public void setPreferredWidth(int preferredWidth) {
0N/A int old = this.preferredWidth;
0N/A this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth);
0N/A firePropertyChange("preferredWidth", old, this.preferredWidth);
0N/A }
0N/A
0N/A /**
0N/A * Returns the preferred width of the <code>TableColumn</code>.
0N/A * The default preferred width is 75.
0N/A *
0N/A * @return the <code>preferredWidth</code> property
0N/A * @see #setPreferredWidth
0N/A */
0N/A public int getPreferredWidth() {
0N/A return preferredWidth;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>TableColumn</code>'s minimum width to
0N/A * <code>minWidth</code>,
0N/A * adjusting the new minimum width if necessary to ensure that
0N/A * 0 &lt;= <code>minWidth</code> &lt;= <code>maxWidth</code>.
0N/A * For example, if the <code>minWidth</code> argument is negative,
0N/A * this method sets the <code>minWidth</code> property to 0.
0N/A *
0N/A * <p>
0N/A * If the value of the
0N/A * <code>width</code> or <code>preferredWidth</code> property
0N/A * is less than the new minimum width,
0N/A * this method sets that property to the new minimum width.
0N/A *
0N/A * @param minWidth the new minimum width
0N/A * @see #getMinWidth
0N/A * @see #setPreferredWidth
0N/A * @see #setMaxWidth
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The minimum width of the column.
0N/A */
0N/A public void setMinWidth(int minWidth) {
0N/A int old = this.minWidth;
0N/A this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0);
0N/A if (width < this.minWidth) {
0N/A setWidth(this.minWidth);
0N/A }
0N/A if (preferredWidth < this.minWidth) {
0N/A setPreferredWidth(this.minWidth);
0N/A }
0N/A firePropertyChange("minWidth", old, this.minWidth);
0N/A }
0N/A
0N/A /**
0N/A * Returns the minimum width for the <code>TableColumn</code>. The
0N/A * <code>TableColumn</code>'s width can't be made less than this either
0N/A * by the user or programmatically.
0N/A *
0N/A * @return the <code>minWidth</code> property
0N/A * @see #setMinWidth
0N/A * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
0N/A */
0N/A public int getMinWidth() {
0N/A return minWidth;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>TableColumn</code>'s maximum width to
0N/A * <code>maxWidth</code> or,
0N/A * if <code>maxWidth</code> is less than the minimum width,
0N/A * to the minimum width.
0N/A *
0N/A * <p>
0N/A * If the value of the
0N/A * <code>width</code> or <code>preferredWidth</code> property
0N/A * is more than the new maximum width,
0N/A * this method sets that property to the new maximum width.
0N/A *
0N/A * @param maxWidth the new maximum width
0N/A * @see #getMaxWidth
0N/A * @see #setPreferredWidth
0N/A * @see #setMinWidth
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The maximum width of the column.
0N/A */
0N/A public void setMaxWidth(int maxWidth) {
0N/A int old = this.maxWidth;
0N/A this.maxWidth = Math.max(minWidth, maxWidth);
0N/A if (width > this.maxWidth) {
0N/A setWidth(this.maxWidth);
0N/A }
0N/A if (preferredWidth > this.maxWidth) {
0N/A setPreferredWidth(this.maxWidth);
0N/A }
0N/A firePropertyChange("maxWidth", old, this.maxWidth);
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum width for the <code>TableColumn</code>. The
0N/A * <code>TableColumn</code>'s width can't be made larger than this
0N/A * either by the user or programmatically. The default maxWidth
0N/A * is Integer.MAX_VALUE.
0N/A *
0N/A * @return the <code>maxWidth</code> property
0N/A * @see #setMaxWidth
0N/A */
0N/A public int getMaxWidth() {
0N/A return maxWidth;
0N/A }
0N/A
0N/A /**
0N/A * Sets whether this column can be resized.
0N/A *
0N/A * @param isResizable if true, resizing is allowed; otherwise false
0N/A * @see #getResizable
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Whether or not this column can be resized.
0N/A */
0N/A public void setResizable(boolean isResizable) {
0N/A boolean old = this.isResizable;
0N/A this.isResizable = isResizable;
0N/A firePropertyChange("isResizable", old, this.isResizable);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the user is allowed to resize the
0N/A * <code>TableColumn</code>'s
0N/A * width, false otherwise. You can change the width programmatically
0N/A * regardless of this setting. The default is true.
0N/A *
0N/A * @return the <code>isResizable</code> property
0N/A * @see #setResizable
0N/A */
0N/A public boolean getResizable() {
0N/A return isResizable;
0N/A }
0N/A
0N/A /**
0N/A * Resizes the <code>TableColumn</code> to fit the width of its header cell.
0N/A * This method does nothing if the header renderer is <code>null</code>
0N/A * (the default case). Otherwise, it sets the minimum, maximum and preferred
0N/A * widths of this column to the widths of the minimum, maximum and preferred
0N/A * sizes of the Component delivered by the header renderer.
0N/A * The transient "width" property of this TableColumn is also set to the
0N/A * preferred width. Note this method is not used internally by the table
0N/A * package.
0N/A *
0N/A * @see #setPreferredWidth
0N/A */
0N/A public void sizeWidthToFit() {
0N/A if (headerRenderer == null) {
0N/A return;
0N/A }
0N/A Component c = headerRenderer.getTableCellRendererComponent(null,
0N/A getHeaderValue(), false, false, 0, 0);
0N/A
0N/A setMinWidth(c.getMinimumSize().width);
0N/A setMaxWidth(c.getMaximumSize().width);
0N/A setPreferredWidth(c.getPreferredSize().width);
0N/A
0N/A setWidth(getPreferredWidth());
0N/A }
0N/A
0N/A /**
0N/A * This field was not used in previous releases and there are
0N/A * currently no plans to support it in the future.
0N/A *
0N/A * @deprecated as of Java 2 platform v1.3
0N/A */
0N/A @Deprecated
0N/A public void disableResizedPosting() {
0N/A resizedPostingDisableCount++;
0N/A }
0N/A
0N/A /**
0N/A * This field was not used in previous releases and there are
0N/A * currently no plans to support it in the future.
0N/A *
0N/A * @deprecated as of Java 2 platform v1.3
0N/A */
0N/A @Deprecated
0N/A public void enableResizedPosting() {
0N/A resizedPostingDisableCount--;
0N/A }
0N/A
0N/A//
0N/A// Property Change Support
0N/A//
0N/A
0N/A /**
0N/A * Adds a <code>PropertyChangeListener</code> to the listener list.
0N/A * The listener is registered for all properties.
0N/A * <p>
0N/A * A <code>PropertyChangeEvent</code> will get fired in response to an
0N/A * explicit call to <code>setFont</code>, <code>setBackground</code>,
0N/A * or <code>setForeground</code> on the
0N/A * current component. Note that if the current component is
0N/A * inheriting its foreground, background, or font from its
0N/A * container, then no event will be fired in response to a
0N/A * change in the inherited property.
0N/A *
0N/A * @param listener the listener to be added
0N/A *
0N/A */
0N/A public synchronized void addPropertyChangeListener(
0N/A PropertyChangeListener listener) {
0N/A if (changeSupport == null) {
0N/A changeSupport = new SwingPropertyChangeSupport(this);
0N/A }
0N/A changeSupport.addPropertyChangeListener(listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes a <code>PropertyChangeListener</code> from the listener list.
0N/A * The <code>PropertyChangeListener</code> to be removed was registered
0N/A * for all properties.
0N/A *
0N/A * @param listener the listener to be removed
0N/A *
0N/A */
0N/A
0N/A public synchronized void removePropertyChangeListener(
0N/A PropertyChangeListener listener) {
0N/A if (changeSupport != null) {
0N/A changeSupport.removePropertyChangeListener(listener);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the <code>PropertyChangeListener</code>s added
0N/A * to this TableColumn with addPropertyChangeListener().
0N/A *
0N/A * @return all of the <code>PropertyChangeListener</code>s added or an empty
0N/A * array if no listeners have been added
0N/A * @since 1.4
0N/A */
0N/A public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
0N/A if (changeSupport == null) {
0N/A return new PropertyChangeListener[0];
0N/A }
0N/A return changeSupport.getPropertyChangeListeners();
0N/A }
0N/A
0N/A//
0N/A// Protected Methods
0N/A//
0N/A
0N/A /**
0N/A * As of Java 2 platform v1.3, this method is not called by the <code>TableColumn</code>
0N/A * constructor. Previously this method was used by the
0N/A * <code>TableColumn</code> to create a default header renderer.
0N/A * As of Java 2 platform v1.3, the default header renderer is <code>null</code>.
0N/A * <code>JTableHeader</code> now provides its own shared default
0N/A * renderer, just as the <code>JTable</code> does for its cell renderers.
0N/A *
0N/A * @return the default header renderer
0N/A * @see javax.swing.table.JTableHeader#createDefaultRenderer()
0N/A */
0N/A protected TableCellRenderer createDefaultHeaderRenderer() {
0N/A DefaultTableCellRenderer label = new DefaultTableCellRenderer() {
0N/A public Component getTableCellRendererComponent(JTable table, Object value,
0N/A boolean isSelected, boolean hasFocus, int row, int column) {
0N/A if (table != null) {
0N/A JTableHeader header = table.getTableHeader();
0N/A if (header != null) {
0N/A setForeground(header.getForeground());
0N/A setBackground(header.getBackground());
0N/A setFont(header.getFont());
0N/A }
0N/A }
0N/A
0N/A setText((value == null) ? "" : value.toString());
0N/A setBorder(UIManager.getBorder("TableHeader.cellBorder"));
0N/A return this;
0N/A }
0N/A };
0N/A label.setHorizontalAlignment(JLabel.CENTER);
0N/A return label;
0N/A }
0N/A
0N/A} // End of class TableColumn