jdk/src/share/classes/javax/swing/table/TableColumn.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.table;
  27 
  28 import javax.swing.*;
  29 import javax.swing.border.*;
  30 import javax.swing.event.SwingPropertyChangeSupport;
  31 import java.lang.Integer;
  32 import java.awt.Color;
  33 import java.awt.Component;
  34 import java.io.Serializable;
  35 import java.beans.PropertyChangeEvent;
  36 import java.beans.PropertyChangeListener;
  37 
  38 /**
  39  *  A <code>TableColumn</code> represents all the attributes of a column in a
  40  *  <code>JTable</code>, such as width, resizability, minimum and maximum width.
  41  *  In addition, the <code>TableColumn</code> provides slots for a renderer and
  42  *  an editor that can be used to display and edit the values in this column.
  43  *  <p>
  44  *  It is also possible to specify renderers and editors on a per type basis
  45  *  rather than a per column basis - see the
  46  *  <code>setDefaultRenderer</code> method in the <code>JTable</code> class.
  47  *  This default mechanism is only used when the renderer (or
  48  *  editor) in the <code>TableColumn</code> is <code>null</code>.
  49  * <p>
  50  *  The <code>TableColumn</code> stores the link between the columns in the
  51  *  <code>JTable</code> and the columns in the <code>TableModel</code>.
  52  *  The <code>modelIndex</code> is the column in the
  53  *  <code>TableModel</code>, which will be queried for the data values for the
  54  *  cells in this column. As the column moves around in the view this
  55  *  <code>modelIndex</code> does not change.


 292     }
 293 
 294     private void firePropertyChange(String propertyName, int oldValue, int newValue) {
 295         if (oldValue != newValue) {
 296             firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
 297         }
 298     }
 299 
 300     private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
 301         if (oldValue != newValue) {
 302             firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
 303         }
 304     }
 305 
 306     /**
 307      * Sets the model index for this column. The model index is the
 308      * index of the column in the model that will be displayed by this
 309      * <code>TableColumn</code>. As the <code>TableColumn</code>
 310      * is moved around in the view the model index remains constant.
 311      * @param  modelIndex  the new modelIndex
 312      * @beaninfo
 313      *  bound: true
 314      *  description: The model index.
 315      */


 316     public void setModelIndex(int modelIndex) {
 317         int old = this.modelIndex;
 318         this.modelIndex = modelIndex;
 319         firePropertyChange("modelIndex", old, modelIndex);
 320     }
 321 
 322     /**
 323      * Returns the model index for this column.
 324      * @return the <code>modelIndex</code> property
 325      */
 326     public int getModelIndex() {
 327         return modelIndex;
 328     }
 329 
 330     /**
 331      * Sets the <code>TableColumn</code>'s identifier to
 332      * <code>anIdentifier</code>. <p>
 333      * Note: identifiers are not used by the <code>JTable</code>,
 334      * they are purely a
 335      * convenience for the external tagging and location of columns.
 336      *
 337      * @param      identifier           an identifier for this column
 338      * @see        #getIdentifier
 339      * @beaninfo
 340      *  bound: true
 341      *  description: A unique identifier for this column.
 342      */


 343     public void setIdentifier(Object identifier) {
 344         Object old = this.identifier;
 345         this.identifier = identifier;
 346         firePropertyChange("identifier", old, identifier);
 347     }
 348 
 349 
 350     /**
 351      *  Returns the <code>identifier</code> object for this column.
 352      *  Note identifiers are not used by <code>JTable</code>,
 353      *  they are purely a convenience for external use.
 354      *  If the <code>identifier</code> is <code>null</code>,
 355      *  <code>getIdentifier()</code> returns <code>getHeaderValue</code>
 356      *  as a default.
 357      *
 358      * @return  the <code>identifier</code> property
 359      * @see     #setIdentifier
 360      */
 361     public Object getIdentifier() {
 362         return (identifier != null) ? identifier : getHeaderValue();
 363 
 364     }
 365 
 366     /**
 367      * Sets the <code>Object</code> whose string representation will be
 368      * used as the value for the <code>headerRenderer</code>.  When the
 369      * <code>TableColumn</code> is created, the default <code>headerValue</code>
 370      * is <code>null</code>.
 371      * @param headerValue  the new headerValue
 372      * @see       #getHeaderValue
 373      * @beaninfo
 374      *  bound: true
 375      *  description: The text to be used by the header renderer.
 376      */


 377     public void setHeaderValue(Object headerValue) {
 378         Object old = this.headerValue;
 379         this.headerValue = headerValue;
 380         firePropertyChange("headerValue", old, headerValue);
 381     }
 382 
 383     /**
 384      * Returns the <code>Object</code> used as the value for the header
 385      * renderer.
 386      *
 387      * @return  the <code>headerValue</code> property
 388      * @see     #setHeaderValue
 389      */
 390     public Object getHeaderValue() {
 391         return headerValue;
 392     }
 393 
 394     //
 395     // Renderers and Editors
 396     //
 397 
 398     /**
 399      * Sets the <code>TableCellRenderer</code> used to draw the
 400      * <code>TableColumn</code>'s header to <code>headerRenderer</code>.
 401      * <p>
 402      * It is the header renderers responsibility to render the sorting
 403      * indicator.  If you are using sorting and specify a renderer your
 404      * renderer must render the sorting indication.
 405      *
 406      * @param headerRenderer  the new headerRenderer
 407      *
 408      * @see       #getHeaderRenderer
 409      * @beaninfo
 410      *  bound: true
 411      *  description: The header renderer.
 412      */


 413     public void setHeaderRenderer(TableCellRenderer headerRenderer) {
 414         TableCellRenderer old = this.headerRenderer;
 415         this.headerRenderer = headerRenderer;
 416         firePropertyChange("headerRenderer", old, headerRenderer);
 417     }
 418 
 419     /**
 420      * Returns the <code>TableCellRenderer</code> used to draw the header of the
 421      * <code>TableColumn</code>. When the <code>headerRenderer</code> is
 422      * <code>null</code>, the <code>JTableHeader</code>
 423      * uses its <code>defaultRenderer</code>. The default value for a
 424      * <code>headerRenderer</code> is <code>null</code>.
 425      *
 426      * @return  the <code>headerRenderer</code> property
 427      * @see     #setHeaderRenderer
 428      * @see     #setHeaderValue
 429      * @see     javax.swing.table.JTableHeader#getDefaultRenderer()
 430      */
 431     public TableCellRenderer getHeaderRenderer() {
 432         return headerRenderer;
 433     }
 434 
 435     /**
 436      * Sets the <code>TableCellRenderer</code> used by <code>JTable</code>
 437      * to draw individual values for this column.
 438      *
 439      * @param cellRenderer  the new cellRenderer
 440      * @see     #getCellRenderer
 441      * @beaninfo
 442      *  bound: true
 443      *  description: The renderer to use for cell values.
 444      */


 445     public void setCellRenderer(TableCellRenderer cellRenderer) {
 446         TableCellRenderer old = this.cellRenderer;
 447         this.cellRenderer = cellRenderer;
 448         firePropertyChange("cellRenderer", old, cellRenderer);
 449     }
 450 
 451     /**
 452      * Returns the <code>TableCellRenderer</code> used by the
 453      * <code>JTable</code> to draw
 454      * values for this column.  The <code>cellRenderer</code> of the column
 455      * not only controls the visual look for the column, but is also used to
 456      * interpret the value object supplied by the <code>TableModel</code>.
 457      * When the <code>cellRenderer</code> is <code>null</code>,
 458      * the <code>JTable</code> uses a default renderer based on the
 459      * class of the cells in that column. The default value for a
 460      * <code>cellRenderer</code> is <code>null</code>.
 461      *
 462      * @return  the <code>cellRenderer</code> property
 463      * @see     #setCellRenderer
 464      * @see     JTable#setDefaultRenderer
 465      */
 466     public TableCellRenderer getCellRenderer() {
 467         return cellRenderer;
 468     }
 469 
 470     /**
 471      * Sets the editor to used by when a cell in this column is edited.
 472      *
 473      * @param cellEditor  the new cellEditor
 474      * @see     #getCellEditor
 475      * @beaninfo
 476      *  bound: true
 477      *  description: The editor to use for cell values.
 478      */


 479     public void setCellEditor(TableCellEditor cellEditor){
 480         TableCellEditor old = this.cellEditor;
 481         this.cellEditor = cellEditor;
 482         firePropertyChange("cellEditor", old, cellEditor);
 483     }
 484 
 485     /**
 486      * Returns the <code>TableCellEditor</code> used by the
 487      * <code>JTable</code> to edit values for this column.  When the
 488      * <code>cellEditor</code> is <code>null</code>, the <code>JTable</code>
 489      * uses a default editor based on the
 490      * class of the cells in that column. The default value for a
 491      * <code>cellEditor</code> is <code>null</code>.
 492      *
 493      * @return  the <code>cellEditor</code> property
 494      * @see     #setCellEditor
 495      * @see     JTable#setDefaultEditor
 496      */
 497     public TableCellEditor getCellEditor() {
 498         return cellEditor;
 499     }
 500 
 501     /**
 502      * This method should not be used to set the widths of columns in the
 503      * <code>JTable</code>, use <code>setPreferredWidth</code> instead.
 504      * Like a layout manager in the
 505      * AWT, the <code>JTable</code> adjusts a column's width automatically
 506      * whenever the
 507      * table itself changes size, or a column's preferred width is changed.
 508      * Setting widths programmatically therefore has no long term effect.
 509      * <p>
 510      * This method sets this column's width to <code>width</code>.
 511      * If <code>width</code> exceeds the minimum or maximum width,
 512      * it is adjusted to the appropriate limiting value.
 513      * @param  width  the new width
 514      * @see     #getWidth
 515      * @see     #setMinWidth
 516      * @see     #setMaxWidth
 517      * @see     #setPreferredWidth
 518      * @see     JTable#doLayout()
 519      * @beaninfo
 520      *  bound: true
 521      *  description: The width of the column.
 522      */


 523     public void setWidth(int width) {
 524         int old = this.width;
 525         this.width = Math.min(Math.max(width, minWidth), maxWidth);
 526         firePropertyChange("width", old, this.width);
 527     }
 528 
 529     /**
 530      * Returns the width of the <code>TableColumn</code>. The default width is
 531      * 75.
 532      *
 533      * @return  the <code>width</code> property
 534      * @see     #setWidth
 535      */
 536     public int getWidth() {
 537         return width;
 538     }
 539 
 540     /**
 541      * Sets this column's preferred width to <code>preferredWidth</code>.
 542      * If <code>preferredWidth</code> exceeds the minimum or maximum width,
 543      * it is adjusted to the appropriate limiting value.
 544      * <p>
 545      * For details on how the widths of columns in the <code>JTable</code>
 546      * (and <code>JTableHeader</code>) are calculated from the
 547      * <code>preferredWidth</code>,
 548      * see the <code>doLayout</code> method in <code>JTable</code>.
 549      *
 550      * @param  preferredWidth the new preferred width
 551      * @see     #getPreferredWidth
 552      * @see     JTable#doLayout()
 553      * @beaninfo
 554      *  bound: true
 555      *  description: The preferred width of the column.
 556      */


 557     public void setPreferredWidth(int preferredWidth) {
 558         int old = this.preferredWidth;
 559         this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth);
 560         firePropertyChange("preferredWidth", old, this.preferredWidth);
 561     }
 562 
 563     /**
 564      * Returns the preferred width of the <code>TableColumn</code>.
 565      * The default preferred width is 75.
 566      *
 567      * @return  the <code>preferredWidth</code> property
 568      * @see     #setPreferredWidth
 569      */
 570     public int getPreferredWidth() {
 571         return preferredWidth;
 572     }
 573 
 574     /**
 575      * Sets the <code>TableColumn</code>'s minimum width to
 576      * <code>minWidth</code>,
 577      * adjusting the new minimum width if necessary to ensure that
 578      * 0 &lt;= <code>minWidth</code> &lt;= <code>maxWidth</code>.
 579      * For example, if the <code>minWidth</code> argument is negative,
 580      * this method sets the <code>minWidth</code> property to 0.
 581      *
 582      * <p>
 583      * If the value of the
 584      * <code>width</code> or <code>preferredWidth</code> property
 585      * is less than the new minimum width,
 586      * this method sets that property to the new minimum width.
 587      *
 588      * @param minWidth  the new minimum width
 589      * @see     #getMinWidth
 590      * @see     #setPreferredWidth
 591      * @see     #setMaxWidth
 592      * @beaninfo
 593      *  bound: true
 594      *  description: The minimum width of the column.
 595      */


 596     public void setMinWidth(int minWidth) {
 597         int old = this.minWidth;
 598         this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0);
 599         if (width < this.minWidth) {
 600             setWidth(this.minWidth);
 601         }
 602         if (preferredWidth < this.minWidth) {
 603             setPreferredWidth(this.minWidth);
 604         }
 605         firePropertyChange("minWidth", old, this.minWidth);
 606     }
 607 
 608     /**
 609      * Returns the minimum width for the <code>TableColumn</code>. The
 610      * <code>TableColumn</code>'s width can't be made less than this either
 611      * by the user or programmatically.
 612      *
 613      * @return  the <code>minWidth</code> property
 614      * @see     #setMinWidth
 615      * @see     #TableColumn(int, int, TableCellRenderer, TableCellEditor)


 617     public int getMinWidth() {
 618         return minWidth;
 619     }
 620 
 621     /**
 622      * Sets the <code>TableColumn</code>'s maximum width to
 623      * <code>maxWidth</code> or,
 624      * if <code>maxWidth</code> is less than the minimum width,
 625      * to the minimum width.
 626      *
 627      * <p>
 628      * If the value of the
 629      * <code>width</code> or <code>preferredWidth</code> property
 630      * is more than the new maximum width,
 631      * this method sets that property to the new maximum width.
 632      *
 633      * @param maxWidth  the new maximum width
 634      * @see     #getMaxWidth
 635      * @see     #setPreferredWidth
 636      * @see     #setMinWidth
 637      * @beaninfo
 638      *  bound: true
 639      *  description: The maximum width of the column.
 640      */


 641     public void setMaxWidth(int maxWidth) {
 642         int old = this.maxWidth;
 643         this.maxWidth = Math.max(minWidth, maxWidth);
 644         if (width > this.maxWidth) {
 645             setWidth(this.maxWidth);
 646         }
 647         if (preferredWidth > this.maxWidth) {
 648             setPreferredWidth(this.maxWidth);
 649         }
 650         firePropertyChange("maxWidth", old, this.maxWidth);
 651     }
 652 
 653     /**
 654      * Returns the maximum width for the <code>TableColumn</code>. The
 655      * <code>TableColumn</code>'s width can't be made larger than this
 656      * either by the user or programmatically.  The default maxWidth
 657      * is Integer.MAX_VALUE.
 658      *
 659      * @return  the <code>maxWidth</code> property
 660      * @see     #setMaxWidth
 661      */
 662     public int getMaxWidth() {
 663         return maxWidth;
 664     }
 665 
 666     /**
 667      * Sets whether this column can be resized.
 668      *
 669      * @param isResizable  if true, resizing is allowed; otherwise false
 670      * @see     #getResizable
 671      * @beaninfo
 672      *  bound: true
 673      *  description: Whether or not this column can be resized.
 674      */


 675     public void setResizable(boolean isResizable) {
 676         boolean old = this.isResizable;
 677         this.isResizable = isResizable;
 678         firePropertyChange("isResizable", old, this.isResizable);
 679     }
 680 
 681     /**
 682      * Returns true if the user is allowed to resize the
 683      * <code>TableColumn</code>'s
 684      * width, false otherwise. You can change the width programmatically
 685      * regardless of this setting.  The default is true.
 686      *
 687      * @return  the <code>isResizable</code> property
 688      * @see     #setResizable
 689      */
 690     public boolean getResizable() {
 691         return isResizable;
 692     }
 693 
 694     /**




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */

  25 package javax.swing.table;
  26 
  27 import javax.swing.*;

  28 import javax.swing.event.SwingPropertyChangeSupport;
  29 import java.lang.Integer;

  30 import java.awt.Component;
  31 import java.io.Serializable;
  32 import java.beans.BeanProperty;
  33 import java.beans.PropertyChangeListener;
  34 
  35 /**
  36  *  A <code>TableColumn</code> represents all the attributes of a column in a
  37  *  <code>JTable</code>, such as width, resizability, minimum and maximum width.
  38  *  In addition, the <code>TableColumn</code> provides slots for a renderer and
  39  *  an editor that can be used to display and edit the values in this column.
  40  *  <p>
  41  *  It is also possible to specify renderers and editors on a per type basis
  42  *  rather than a per column basis - see the
  43  *  <code>setDefaultRenderer</code> method in the <code>JTable</code> class.
  44  *  This default mechanism is only used when the renderer (or
  45  *  editor) in the <code>TableColumn</code> is <code>null</code>.
  46  * <p>
  47  *  The <code>TableColumn</code> stores the link between the columns in the
  48  *  <code>JTable</code> and the columns in the <code>TableModel</code>.
  49  *  The <code>modelIndex</code> is the column in the
  50  *  <code>TableModel</code>, which will be queried for the data values for the
  51  *  cells in this column. As the column moves around in the view this
  52  *  <code>modelIndex</code> does not change.


 289     }
 290 
 291     private void firePropertyChange(String propertyName, int oldValue, int newValue) {
 292         if (oldValue != newValue) {
 293             firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
 294         }
 295     }
 296 
 297     private void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
 298         if (oldValue != newValue) {
 299             firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
 300         }
 301     }
 302 
 303     /**
 304      * Sets the model index for this column. The model index is the
 305      * index of the column in the model that will be displayed by this
 306      * <code>TableColumn</code>. As the <code>TableColumn</code>
 307      * is moved around in the view the model index remains constant.
 308      * @param  modelIndex  the new modelIndex



 309      */
 310     @BeanProperty(description
 311             = "The model index.")
 312     public void setModelIndex(int modelIndex) {
 313         int old = this.modelIndex;
 314         this.modelIndex = modelIndex;
 315         firePropertyChange("modelIndex", old, modelIndex);
 316     }
 317 
 318     /**
 319      * Returns the model index for this column.
 320      * @return the <code>modelIndex</code> property
 321      */
 322     public int getModelIndex() {
 323         return modelIndex;
 324     }
 325 
 326     /**
 327      * Sets the <code>TableColumn</code>'s identifier to
 328      * <code>anIdentifier</code>. <p>
 329      * Note: identifiers are not used by the <code>JTable</code>,
 330      * they are purely a
 331      * convenience for the external tagging and location of columns.
 332      *
 333      * @param      identifier           an identifier for this column
 334      * @see        #getIdentifier



 335      */
 336     @BeanProperty(description
 337             = "A unique identifier for this column.")
 338     public void setIdentifier(Object identifier) {
 339         Object old = this.identifier;
 340         this.identifier = identifier;
 341         firePropertyChange("identifier", old, identifier);
 342     }
 343 
 344 
 345     /**
 346      *  Returns the <code>identifier</code> object for this column.
 347      *  Note identifiers are not used by <code>JTable</code>,
 348      *  they are purely a convenience for external use.
 349      *  If the <code>identifier</code> is <code>null</code>,
 350      *  <code>getIdentifier()</code> returns <code>getHeaderValue</code>
 351      *  as a default.
 352      *
 353      * @return  the <code>identifier</code> property
 354      * @see     #setIdentifier
 355      */
 356     public Object getIdentifier() {
 357         return (identifier != null) ? identifier : getHeaderValue();
 358 
 359     }
 360 
 361     /**
 362      * Sets the <code>Object</code> whose string representation will be
 363      * used as the value for the <code>headerRenderer</code>.  When the
 364      * <code>TableColumn</code> is created, the default <code>headerValue</code>
 365      * is <code>null</code>.
 366      * @param headerValue  the new headerValue
 367      * @see       #getHeaderValue



 368      */
 369     @BeanProperty(description
 370             = "The text to be used by the header renderer.")
 371     public void setHeaderValue(Object headerValue) {
 372         Object old = this.headerValue;
 373         this.headerValue = headerValue;
 374         firePropertyChange("headerValue", old, headerValue);
 375     }
 376 
 377     /**
 378      * Returns the <code>Object</code> used as the value for the header
 379      * renderer.
 380      *
 381      * @return  the <code>headerValue</code> property
 382      * @see     #setHeaderValue
 383      */
 384     public Object getHeaderValue() {
 385         return headerValue;
 386     }
 387 
 388     //
 389     // Renderers and Editors
 390     //
 391 
 392     /**
 393      * Sets the <code>TableCellRenderer</code> used to draw the
 394      * <code>TableColumn</code>'s header to <code>headerRenderer</code>.
 395      * <p>
 396      * It is the header renderers responsibility to render the sorting
 397      * indicator.  If you are using sorting and specify a renderer your
 398      * renderer must render the sorting indication.
 399      *
 400      * @param headerRenderer  the new headerRenderer
 401      *
 402      * @see       #getHeaderRenderer



 403      */
 404     @BeanProperty(description
 405             = "The header renderer.")
 406     public void setHeaderRenderer(TableCellRenderer headerRenderer) {
 407         TableCellRenderer old = this.headerRenderer;
 408         this.headerRenderer = headerRenderer;
 409         firePropertyChange("headerRenderer", old, headerRenderer);
 410     }
 411 
 412     /**
 413      * Returns the <code>TableCellRenderer</code> used to draw the header of the
 414      * <code>TableColumn</code>. When the <code>headerRenderer</code> is
 415      * <code>null</code>, the <code>JTableHeader</code>
 416      * uses its <code>defaultRenderer</code>. The default value for a
 417      * <code>headerRenderer</code> is <code>null</code>.
 418      *
 419      * @return  the <code>headerRenderer</code> property
 420      * @see     #setHeaderRenderer
 421      * @see     #setHeaderValue
 422      * @see     javax.swing.table.JTableHeader#getDefaultRenderer()
 423      */
 424     public TableCellRenderer getHeaderRenderer() {
 425         return headerRenderer;
 426     }
 427 
 428     /**
 429      * Sets the <code>TableCellRenderer</code> used by <code>JTable</code>
 430      * to draw individual values for this column.
 431      *
 432      * @param cellRenderer  the new cellRenderer
 433      * @see     #getCellRenderer



 434      */
 435     @BeanProperty(description
 436             = "The renderer to use for cell values.")
 437     public void setCellRenderer(TableCellRenderer cellRenderer) {
 438         TableCellRenderer old = this.cellRenderer;
 439         this.cellRenderer = cellRenderer;
 440         firePropertyChange("cellRenderer", old, cellRenderer);
 441     }
 442 
 443     /**
 444      * Returns the <code>TableCellRenderer</code> used by the
 445      * <code>JTable</code> to draw
 446      * values for this column.  The <code>cellRenderer</code> of the column
 447      * not only controls the visual look for the column, but is also used to
 448      * interpret the value object supplied by the <code>TableModel</code>.
 449      * When the <code>cellRenderer</code> is <code>null</code>,
 450      * the <code>JTable</code> uses a default renderer based on the
 451      * class of the cells in that column. The default value for a
 452      * <code>cellRenderer</code> is <code>null</code>.
 453      *
 454      * @return  the <code>cellRenderer</code> property
 455      * @see     #setCellRenderer
 456      * @see     JTable#setDefaultRenderer
 457      */
 458     public TableCellRenderer getCellRenderer() {
 459         return cellRenderer;
 460     }
 461 
 462     /**
 463      * Sets the editor to used by when a cell in this column is edited.
 464      *
 465      * @param cellEditor  the new cellEditor
 466      * @see     #getCellEditor



 467      */
 468     @BeanProperty(description
 469             = "The editor to use for cell values.")
 470     public void setCellEditor(TableCellEditor cellEditor){
 471         TableCellEditor old = this.cellEditor;
 472         this.cellEditor = cellEditor;
 473         firePropertyChange("cellEditor", old, cellEditor);
 474     }
 475 
 476     /**
 477      * Returns the <code>TableCellEditor</code> used by the
 478      * <code>JTable</code> to edit values for this column.  When the
 479      * <code>cellEditor</code> is <code>null</code>, the <code>JTable</code>
 480      * uses a default editor based on the
 481      * class of the cells in that column. The default value for a
 482      * <code>cellEditor</code> is <code>null</code>.
 483      *
 484      * @return  the <code>cellEditor</code> property
 485      * @see     #setCellEditor
 486      * @see     JTable#setDefaultEditor
 487      */
 488     public TableCellEditor getCellEditor() {
 489         return cellEditor;
 490     }
 491 
 492     /**
 493      * This method should not be used to set the widths of columns in the
 494      * <code>JTable</code>, use <code>setPreferredWidth</code> instead.
 495      * Like a layout manager in the
 496      * AWT, the <code>JTable</code> adjusts a column's width automatically
 497      * whenever the
 498      * table itself changes size, or a column's preferred width is changed.
 499      * Setting widths programmatically therefore has no long term effect.
 500      * <p>
 501      * This method sets this column's width to <code>width</code>.
 502      * If <code>width</code> exceeds the minimum or maximum width,
 503      * it is adjusted to the appropriate limiting value.
 504      * @param  width  the new width
 505      * @see     #getWidth
 506      * @see     #setMinWidth
 507      * @see     #setMaxWidth
 508      * @see     #setPreferredWidth
 509      * @see     JTable#doLayout()



 510      */
 511     @BeanProperty(description
 512             = "The width of the column.")
 513     public void setWidth(int width) {
 514         int old = this.width;
 515         this.width = Math.min(Math.max(width, minWidth), maxWidth);
 516         firePropertyChange("width", old, this.width);
 517     }
 518 
 519     /**
 520      * Returns the width of the <code>TableColumn</code>. The default width is
 521      * 75.
 522      *
 523      * @return  the <code>width</code> property
 524      * @see     #setWidth
 525      */
 526     public int getWidth() {
 527         return width;
 528     }
 529 
 530     /**
 531      * Sets this column's preferred width to <code>preferredWidth</code>.
 532      * If <code>preferredWidth</code> exceeds the minimum or maximum width,
 533      * it is adjusted to the appropriate limiting value.
 534      * <p>
 535      * For details on how the widths of columns in the <code>JTable</code>
 536      * (and <code>JTableHeader</code>) are calculated from the
 537      * <code>preferredWidth</code>,
 538      * see the <code>doLayout</code> method in <code>JTable</code>.
 539      *
 540      * @param  preferredWidth the new preferred width
 541      * @see     #getPreferredWidth
 542      * @see     JTable#doLayout()



 543      */
 544     @BeanProperty(description
 545             = "The preferred width of the column.")
 546     public void setPreferredWidth(int preferredWidth) {
 547         int old = this.preferredWidth;
 548         this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth);
 549         firePropertyChange("preferredWidth", old, this.preferredWidth);
 550     }
 551 
 552     /**
 553      * Returns the preferred width of the <code>TableColumn</code>.
 554      * The default preferred width is 75.
 555      *
 556      * @return  the <code>preferredWidth</code> property
 557      * @see     #setPreferredWidth
 558      */
 559     public int getPreferredWidth() {
 560         return preferredWidth;
 561     }
 562 
 563     /**
 564      * Sets the <code>TableColumn</code>'s minimum width to
 565      * <code>minWidth</code>,
 566      * adjusting the new minimum width if necessary to ensure that
 567      * 0 &lt;= <code>minWidth</code> &lt;= <code>maxWidth</code>.
 568      * For example, if the <code>minWidth</code> argument is negative,
 569      * this method sets the <code>minWidth</code> property to 0.
 570      *
 571      * <p>
 572      * If the value of the
 573      * <code>width</code> or <code>preferredWidth</code> property
 574      * is less than the new minimum width,
 575      * this method sets that property to the new minimum width.
 576      *
 577      * @param minWidth  the new minimum width
 578      * @see     #getMinWidth
 579      * @see     #setPreferredWidth
 580      * @see     #setMaxWidth



 581      */
 582     @BeanProperty(description
 583             = "The minimum width of the column.")
 584     public void setMinWidth(int minWidth) {
 585         int old = this.minWidth;
 586         this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0);
 587         if (width < this.minWidth) {
 588             setWidth(this.minWidth);
 589         }
 590         if (preferredWidth < this.minWidth) {
 591             setPreferredWidth(this.minWidth);
 592         }
 593         firePropertyChange("minWidth", old, this.minWidth);
 594     }
 595 
 596     /**
 597      * Returns the minimum width for the <code>TableColumn</code>. The
 598      * <code>TableColumn</code>'s width can't be made less than this either
 599      * by the user or programmatically.
 600      *
 601      * @return  the <code>minWidth</code> property
 602      * @see     #setMinWidth
 603      * @see     #TableColumn(int, int, TableCellRenderer, TableCellEditor)


 605     public int getMinWidth() {
 606         return minWidth;
 607     }
 608 
 609     /**
 610      * Sets the <code>TableColumn</code>'s maximum width to
 611      * <code>maxWidth</code> or,
 612      * if <code>maxWidth</code> is less than the minimum width,
 613      * to the minimum width.
 614      *
 615      * <p>
 616      * If the value of the
 617      * <code>width</code> or <code>preferredWidth</code> property
 618      * is more than the new maximum width,
 619      * this method sets that property to the new maximum width.
 620      *
 621      * @param maxWidth  the new maximum width
 622      * @see     #getMaxWidth
 623      * @see     #setPreferredWidth
 624      * @see     #setMinWidth



 625      */
 626     @BeanProperty(description
 627             = "The maximum width of the column.")
 628     public void setMaxWidth(int maxWidth) {
 629         int old = this.maxWidth;
 630         this.maxWidth = Math.max(minWidth, maxWidth);
 631         if (width > this.maxWidth) {
 632             setWidth(this.maxWidth);
 633         }
 634         if (preferredWidth > this.maxWidth) {
 635             setPreferredWidth(this.maxWidth);
 636         }
 637         firePropertyChange("maxWidth", old, this.maxWidth);
 638     }
 639 
 640     /**
 641      * Returns the maximum width for the <code>TableColumn</code>. The
 642      * <code>TableColumn</code>'s width can't be made larger than this
 643      * either by the user or programmatically.  The default maxWidth
 644      * is Integer.MAX_VALUE.
 645      *
 646      * @return  the <code>maxWidth</code> property
 647      * @see     #setMaxWidth
 648      */
 649     public int getMaxWidth() {
 650         return maxWidth;
 651     }
 652 
 653     /**
 654      * Sets whether this column can be resized.
 655      *
 656      * @param isResizable  if true, resizing is allowed; otherwise false
 657      * @see     #getResizable



 658      */
 659     @BeanProperty(description
 660             = "Whether or not this column can be resized.")
 661     public void setResizable(boolean isResizable) {
 662         boolean old = this.isResizable;
 663         this.isResizable = isResizable;
 664         firePropertyChange("isResizable", old, this.isResizable);
 665     }
 666 
 667     /**
 668      * Returns true if the user is allowed to resize the
 669      * <code>TableColumn</code>'s
 670      * width, false otherwise. You can change the width programmatically
 671      * regardless of this setting.  The default is true.
 672      *
 673      * @return  the <code>isResizable</code> property
 674      * @see     #setResizable
 675      */
 676     public boolean getResizable() {
 677         return isResizable;
 678     }
 679 
 680     /**