KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > table > TableColumn


1 /*
2  * @(#)TableColumn.java 1.60 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.table;
9
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import javax.swing.event.SwingPropertyChangeSupport JavaDoc;
13 import java.lang.Integer JavaDoc;
14 import java.awt.Color JavaDoc;
15 import java.awt.Component JavaDoc;
16 import java.io.Serializable JavaDoc;
17 import java.beans.PropertyChangeEvent JavaDoc;
18 import java.beans.PropertyChangeListener JavaDoc;
19
20 /**
21  * A <code>TableColumn</code> represents all the attributes of a column in a
22  * <code>JTable</code>, such as width, resizibility, minimum and maximum width.
23  * In addition, the <code>TableColumn</code> provides slots for a renderer and
24  * an editor that can be used to display and edit the values in this column.
25  * <p>
26  * It is also possible to specify renderers and editors on a per type basis
27  * rather than a per column basis - see the
28  * <code>setDefaultRenderer</code> method in the <code>JTable</code> class.
29  * This default mechanism is only used when the renderer (or
30  * editor) in the <code>TableColumn</code> is <code>null</code>.
31  * <p>
32  * The <code>TableColumn</code> stores the link between the columns in the
33  * <code>JTable</code> and the columns in the <code>TableModel</code>.
34  * The <code>modelIndex</code> is the column in the
35  * <code>TableModel</code>, which will be queried for the data values for the
36  * cells in this column. As the column moves around in the view this
37  * <code>modelIndex</code> does not change.
38  * <p>
39  * <b>Note:</b> Some implementations may assume that all
40  * <code>TableColumnModel</code>s are unique, therefore we would
41  * recommend that the same <code>TableColumn</code> instance
42  * not be added more than once to a <code>TableColumnModel</code>.
43  * To show <code>TableColumn</code>s with the same column of
44  * data from the model, create a new instance with the same
45  * <code>modelIndex</code>.
46  * <p>
47  * <strong>Warning:</strong>
48  * Serialized objects of this class will not be compatible with
49  * future Swing releases. The current serialization support is
50  * appropriate for short term storage or RMI between applications running
51  * the same version of Swing. As of 1.4, support for long term storage
52  * of all JavaBeans<sup><font size="-2">TM</font></sup>
53  * has been added to the <code>java.beans</code> package.
54  * Please see {@link java.beans.XMLEncoder}.
55  *
56  * @version 1.60 05/18/04
57  * @author Alan Chung
58  * @author Philip Milne
59  * @see javax.swing.table.TableColumnModel
60  *
61  * @see javax.swing.table.DefaultTableColumnModel
62  * @see javax.swing.table.JTableHeader#getDefaultRenderer()
63  * @see JTable#getDefaultRenderer(Class)
64  * @see JTable#getDefaultEditor(Class)
65  * @see JTable#getCellRenderer(int, int)
66  * @see JTable#getCellEditor(int, int)
67  */

68 public class TableColumn extends Object JavaDoc implements Serializable JavaDoc {
69
70     /**
71      * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
72      * properties.
73      */

74     /*
75      * Warning: The value of this constant, "columWidth" is wrong as the
76      * name of the property is "columnWidth".
77      */

78     public final static String JavaDoc COLUMN_WIDTH_PROPERTY = "columWidth";
79
80     /**
81      * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
82      * properties.
83      */

84     public final static String JavaDoc HEADER_VALUE_PROPERTY = "headerValue";
85
86     /**
87      * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
88      * properties.
89      */

90     public final static String JavaDoc HEADER_RENDERER_PROPERTY = "headerRenderer";
91
92     /**
93      * Obsolete as of Java 2 platform v1.3. Please use string literals to identify
94      * properties.
95      */

96     public final static String JavaDoc CELL_RENDERER_PROPERTY = "cellRenderer";
97
98 //
99
// Instance Variables
100
//
101

102     /**
103       * The index of the column in the model which is to be displayed by
104       * this <code>TableColumn</code>. As columns are moved around in the
105       * view <code>modelIndex</code> remains constant.
106       */

107     protected int modelIndex;
108
109     /**
110      * This object is not used internally by the drawing machinery of
111      * the <code>JTable</code>; identifiers may be set in the
112      * <code>TableColumn</code> as as an
113      * optional way to tag and locate table columns. The table package does
114      * not modify or invoke any methods in these identifier objects other
115      * than the <code>equals</code> method which is used in the
116      * <code>getColumnIndex()</code> method in the
117      * <code>DefaultTableColumnModel</code>.
118      */

119     protected Object JavaDoc identifier;
120
121     /** The width of the column. */
122     protected int width;
123
124     /** The minimum width of the column. */
125     protected int minWidth;
126
127     /** The preferred width of the column. */
128     private int preferredWidth;
129
130     /** The maximum width of the column. */
131     protected int maxWidth;
132
133     /** The renderer used to draw the header of the column. */
134     protected TableCellRenderer JavaDoc headerRenderer;
135
136     /** The header value of the column. */
137     protected Object JavaDoc headerValue;
138
139     /** The renderer used to draw the data cells of the column. */
140     protected TableCellRenderer JavaDoc cellRenderer;
141
142     /** The editor used to edit the data cells of the column. */
143     protected TableCellEditor JavaDoc cellEditor;
144
145     /** If true, the user is allowed to resize the column; the default is true. */
146     protected boolean isResizable;
147
148     /**
149      * This field was not used in previous releases and there are
150      * currently no plans to support it in the future.
151      *
152      * @deprecated as of Java 2 platform v1.3
153      */

154     /*
155      * Counter used to disable posting of resizing notifications until the
156      * end of the resize.
157      */

158     @Deprecated JavaDoc
159     transient protected int resizedPostingDisableCount;
160
161     /**
162      * If any <code>PropertyChangeListeners</code> have been registered, the
163      * <code>changeSupport</code> field describes them.
164      */

165     private SwingPropertyChangeSupport JavaDoc changeSupport;
166
167 //
168
// Constructors
169
//
170

171     /**
172      * Cover method, using a default model index of 0,
173      * default width of 75, a <code>null</code> renderer and a
174      * <code>null</code> editor.
175      * This method is intended for serialization.
176      * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
177      */

178     public TableColumn() {
179     this(0);
180     }
181
182     /**
183      * Cover method, using a default width of 75, a <code>null</code>
184      * renderer and a <code>null</code> editor.
185      * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
186      */

187     public TableColumn(int modelIndex) {
188     this(modelIndex, 75, null, null);
189     }
190
191     /**
192      * Cover method, using a <code>null</code> renderer and a
193      * <code>null</code> editor.
194      * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor)
195      */

196     public TableColumn(int modelIndex, int width) {
197     this(modelIndex, width, null, null);
198     }
199
200     /**
201      * Creates and initializes an instance of
202      * <code>TableColumn</code> with <code>modelIndex</code>.
203      * All <code>TableColumn</code> constructors delegate to this one.
204      * The <code>modelIndex</code> is the index of the column
205      * in the model which will supply the data for this column in the table.
206      * The <code>modelIndex</code> does not change as the columns are reordered
207      * in the view. The width parameter is used to set both the
208      * <code>preferredWidth</code> for this
209      * column and the initial width. The renderer and editor are the objects
210      * used respectively to render and edit values in this column. When
211      * these are <code>null</code>, default values, provided by the
212      * <code>getDefaultRenderer</code>
213      * and <code>getDefaultEditor</code> methods in the
214      * <code>JTable</code> class are used to
215      * provide defaults based on the type of the data in this column.
216      * This column-centric rendering strategy can be circumvented by overriding
217      * the <code>getCellRenderer</code> methods in the <code>JTable</code>.
218      * <p>
219      *
220      * @see JTable#getDefaultRenderer(Class)
221      * @see JTable#getDefaultEditor(Class)
222      * @see JTable#getCellRenderer(int, int)
223      * @see JTable#getCellEditor(int, int)
224      */

225     public TableColumn(int modelIndex, int width,
226                  TableCellRenderer JavaDoc cellRenderer,
227                  TableCellEditor JavaDoc cellEditor) {
228     super();
229     this.modelIndex = modelIndex;
230     this.width = width;
231     this.preferredWidth = width;
232
233     this.cellRenderer = cellRenderer;
234     this.cellEditor = cellEditor;
235
236     // Set other instance variables to default values.
237
minWidth = 15;
238     maxWidth = Integer.MAX_VALUE;
239     isResizable = true;
240     resizedPostingDisableCount = 0;
241     headerValue = null;
242     }
243
244 //
245
// Modifying and Querying attributes
246
//
247

248     private void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
249         if (changeSupport != null) {
250             changeSupport.firePropertyChange(propertyName, oldValue, newValue);
251         }
252     }
253
254     private void firePropertyChange(String JavaDoc propertyName, int oldValue, int newValue) {
255         if (oldValue != newValue) {
256             firePropertyChange(propertyName, new Integer JavaDoc(oldValue), new Integer JavaDoc(newValue));
257         }
258     }
259
260     private void firePropertyChange(String JavaDoc propertyName, boolean oldValue, boolean newValue) {
261         if (oldValue != newValue) {
262             firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
263         }
264     }
265
266     /**
267      * Sets the model index for this column. The model index is the
268      * index of the column in the model that will be displayed by this
269      * <code>TableColumn</code>. As the <code>TableColumn</code>
270      * is moved around in the view the model index remains constant.
271      * @param modelIndex the new modelIndex
272      * @beaninfo
273      * bound: true
274      * description: The model index.
275      */

276     public void setModelIndex(int modelIndex) {
277     int old = this.modelIndex;
278     this.modelIndex = modelIndex;
279     firePropertyChange("modelIndex", old, modelIndex);
280     }
281
282     /**
283      * Returns the model index for this column.
284      * @return the <code>modelIndex</code> property
285      */

286     public int getModelIndex() {
287     return modelIndex;
288     }
289
290     /**
291      * Sets the <code>TableColumn</code>'s identifier to
292      * <code>anIdentifier</code>. <p>
293      * Note: identifiers are not used by the <code>JTable</code>,
294      * they are purely a
295      * convenience for the external tagging and location of columns.
296      *
297      * @param identifier an identifier for this column
298      * @see #getIdentifier
299      * @beaninfo
300      * bound: true
301      * description: A unique identifier for this column.
302      */

303     public void setIdentifier(Object JavaDoc identifier) {
304     Object JavaDoc old = this.identifier;
305     this.identifier = identifier;
306     firePropertyChange("identifier", old, identifier);
307     }
308
309
310     /**
311      * Returns the <code>identifier</code> object for this column.
312      * Note identifiers are not used by <code>JTable</code>,
313      * they are purely a convenience for external use.
314      * If the <code>identifier</code> is <code>null</code>,
315      * <code>getIdentifier()</code> returns <code>getHeaderValue</code>
316      * as a default.
317      *
318      * @return the <code>identifier</code> property
319      * @see #setIdentifier
320      */

321     public Object JavaDoc getIdentifier() {
322         return (identifier != null) ? identifier : getHeaderValue();
323
324     }
325
326     /**
327      * Sets the <code>Object</code> whose string representation will be
328      * used as the value for the <code>headerRenderer</code>. When the
329      * <code>TableColumn</code> is created, the default <code>headerValue</code>
330      * is <code>null</code>.
331      * @param headerValue the new headerValue
332      * @see #getHeaderValue
333      * @beaninfo
334      * bound: true
335      * description: The text to be used by the header renderer.
336      */

337     public void setHeaderValue(Object JavaDoc headerValue) {
338     Object JavaDoc old = this.headerValue;
339     this.headerValue = headerValue;
340     firePropertyChange("headerValue", old, headerValue);
341     }
342
343     /**
344      * Returns the <code>Object</code> used as the value for the header
345      * renderer.
346      *
347      * @return the <code>headerValue</code> property
348      * @see #setHeaderValue
349      */

350     public Object JavaDoc getHeaderValue() {
351     return headerValue;
352     }
353
354     //
355
// Renderers and Editors
356
//
357

358     /**
359      * Sets the <code>TableCellRenderer</code> used to draw the
360      * <code>TableColumn</code>'s header to <code>headerRenderer</code>.
361      *
362      * @param headerRenderer the new headerRenderer
363      *
364      * @see #getHeaderRenderer
365      * @beaninfo
366      * bound: true
367      * description: The header renderer.
368      */

369     public void setHeaderRenderer(TableCellRenderer JavaDoc headerRenderer) {
370     TableCellRenderer JavaDoc old = this.headerRenderer;
371     this.headerRenderer = headerRenderer;
372     firePropertyChange("headerRenderer", old, headerRenderer);
373     }
374
375     /**
376      * Returns the <code>TableCellRenderer</code> used to draw the header of the
377      * <code>TableColumn</code>. When the <code>headerRenderer</code> is
378      * <code>null</code>, the <code>JTableHeader</code>
379      * uses its <code>defaultRenderer</code>. The default value for a
380      * <code>headerRenderer</code> is <code>null</code>.
381      *
382      * @return the <code>headerRenderer</code> property
383      * @see #setHeaderRenderer
384      * @see #setHeaderValue
385      * @see javax.swing.table.JTableHeader#getDefaultRenderer()
386      */

387     public TableCellRenderer JavaDoc getHeaderRenderer() {
388     return headerRenderer;
389     }
390
391     /**
392      * Sets the <code>TableCellRenderer</code> used by <code>JTable</code>
393      * to draw individual values for this column.
394      *
395      * @param cellRenderer the new cellRenderer
396      * @see #getCellRenderer
397      * @beaninfo
398      * bound: true
399      * description: The renderer to use for cell values.
400      */

401     public void setCellRenderer(TableCellRenderer JavaDoc cellRenderer) {
402     TableCellRenderer JavaDoc old = this.cellRenderer;
403     this.cellRenderer = cellRenderer;
404     firePropertyChange("cellRenderer", old, cellRenderer);
405     }
406
407     /**
408      * Returns the <code>TableCellRenderer</code> used by the
409      * <code>JTable</code> to draw
410      * values for this column. The <code>cellRenderer</code> of the column
411      * not only controls the visual look for the column, but is also used to
412      * interpret the value object supplied by the <code>TableModel</code>.
413      * When the <code>cellRenderer</code> is <code>null</code>,
414      * the <code>JTable</code> uses a default renderer based on the
415      * class of the cells in that column. The default value for a
416      * <code>cellRenderer</code> is <code>null</code>.
417      *
418      * @return the <code>cellRenderer</code> property
419      * @see #setCellRenderer
420      * @see JTable#setDefaultRenderer
421      */

422     public TableCellRenderer JavaDoc getCellRenderer() {
423     return cellRenderer;
424     }
425
426     /**
427      * Sets the editor to used by when a cell in this column is edited.
428      *
429      * @param cellEditor the new cellEditor
430      * @see #getCellEditor
431      * @beaninfo
432      * bound: true
433      * description: The editor to use for cell values.
434      */

435     public void setCellEditor(TableCellEditor JavaDoc cellEditor){
436     TableCellEditor JavaDoc old = this.cellEditor;
437     this.cellEditor = cellEditor;
438     firePropertyChange("cellEditor", old, cellEditor);
439     }
440
441     /**
442      * Returns the <code>TableCellEditor</code> used by the
443      * <code>JTable</code> to edit values for this column. When the
444      * <code>cellEditor</code> is <code>null</code>, the <code>JTable</code>
445      * uses a default editor based on the
446      * class of the cells in that column. The default value for a
447      * <code>cellEditor</code> is <code>null</code>.
448      *
449      * @return the <code>cellEditor</code> property
450      * @see #setCellEditor
451      * @see JTable#setDefaultEditor
452      */

453     public TableCellEditor JavaDoc getCellEditor() {
454     return cellEditor;
455     }
456
457     /**
458      * This method should not be used to set the widths of columns in the
459      * <code>JTable</code>, use <code>setPreferredWidth</code> instead.
460      * Like a layout manager in the
461      * AWT, the <code>JTable</code> adjusts a column's width automatically
462      * whenever the
463      * table itself changes size, or a column's preferred width is changed.
464      * Setting widths programmatically therefore has no long term effect.
465      * <p>
466      * This method sets this column's width to <code>width</code>.
467      * If <code>width</code> exceeds the minimum or maximum width,
468      * it is adjusted to the appropriate limiting value.
469      * <p>
470      * @param width the new width
471      * @see #getWidth
472      * @see #setMinWidth
473      * @see #setMaxWidth
474      * @see #setPreferredWidth
475      * @see JTable#sizeColumnsToFit(int)
476      * @beaninfo
477      * bound: true
478      * description: The width of the column.
479      */

480     public void setWidth(int width) {
481     int old = this.width;
482     this.width = Math.min(Math.max(width, minWidth), maxWidth);
483     firePropertyChange("width", old, this.width);
484     }
485
486     /**
487      * Returns the width of the <code>TableColumn</code>. The default width is
488      * 75.
489      *
490      * @return the <code>width</code> property
491      * @see #setWidth
492      */

493     public int getWidth() {
494     return width;
495     }
496
497     /**
498      * Sets this column's preferred width to <code>preferredWidth</code>.
499      * If <code>preferredWidth</code> exceeds the minimum or maximum width,
500      * it is adjusted to the appropriate limiting value.
501      * <p>
502      * For details on how the widths of columns in the <code>JTable</code>
503      * (and <code>JTableHeader</code>) are calculated from the
504      * <code>preferredWidth</code>,
505      * see the <code>doLayout</code> method in <code>JTable</code>.
506      *
507      * @param preferredWidth the new preferred width
508      * @see #getPreferredWidth
509      * @see JTable#doLayout()
510      * @beaninfo
511      * bound: true
512      * description: The preferred width of the column.
513      */

514     public void setPreferredWidth(int preferredWidth) {
515     int old = this.preferredWidth;
516     this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth);
517     firePropertyChange("preferredWidth", old, this.preferredWidth);
518     }
519
520     /**
521      * Returns the preferred width of the <code>TableColumn</code>.
522      * The default preferred width is 75.
523      *
524      * @return the <code>preferredWidth</code> property
525      * @see #setPreferredWidth
526      */

527     public int getPreferredWidth() {
528     return preferredWidth;
529     }
530
531     /**
532      * Sets the <code>TableColumn</code>'s minimum width to
533      * <code>minWidth</code>; also adjusts the current width
534      * and preferred width if they are less than this value.
535      *
536      * @param minWidth the new minimum width
537      * @see #getMinWidth
538      * @see #setPreferredWidth
539      * @see #setMaxWidth
540      * @beaninfo
541      * bound: true
542      * description: The minimum width of the column.
543      */

544     public void setMinWidth(int minWidth) {
545     int old = this.minWidth;
546     this.minWidth = Math.max(minWidth, 0);
547     if (width < minWidth) {
548         setWidth(minWidth);
549     }
550     if (preferredWidth < minWidth) {
551         setPreferredWidth(minWidth);
552     }
553     firePropertyChange("minWidth", old, this.minWidth);
554     }
555
556     /**
557      * Returns the minimum width for the <code>TableColumn</code>. The
558      * <code>TableColumn</code>'s width can't be made less than this either
559      * by the user or programmatically. The default minWidth is 15.
560      *
561      * @return the <code>minWidth</code> property
562      * @see #setMinWidth
563      */

564     public int getMinWidth() {
565     return minWidth;
566     }
567
568     /**
569      * Sets the <code>TableColumn</code>'s maximum width to
570      * <code>maxWidth</code>; also adjusts the width and preferred
571      * width if they are greater than this value.
572      *
573      * @param maxWidth the new maximum width
574      * @see #getMaxWidth
575      * @see #setPreferredWidth
576      * @see #setMinWidth
577      * @beaninfo
578      * bound: true
579      * description: The maximum width of the column.
580      */

581     public void setMaxWidth(int maxWidth) {
582     int old = this.maxWidth;
583     this.maxWidth = Math.max(minWidth, maxWidth);
584     if (width > maxWidth) {
585         setWidth(maxWidth);
586     }
587     if (preferredWidth > maxWidth) {
588         setPreferredWidth(maxWidth);
589     }
590     firePropertyChange("maxWidth", old, this.maxWidth);
591     }
592
593     /**
594      * Returns the maximum width for the <code>TableColumn</code>. The
595      * <code>TableColumn</code>'s width can't be made larger than this
596      * either by the user or programmatically. The default maxWidth
597      * is Integer.MAX_VALUE.
598      *
599      * @return the <code>maxWidth</code> property
600      * @see #setMaxWidth
601      */

602     public int getMaxWidth() {
603     return maxWidth;
604     }
605
606     /**
607      * Sets whether this column can be resized.
608      *
609      * @param isResizable if true, resizing is allowed; otherwise false
610      * @see #getResizable
611      * @beaninfo
612      * bound: true
613      * description: Whether or not this column can be resized.
614      */

615     public void setResizable(boolean isResizable) {
616     boolean old = this.isResizable;
617     this.isResizable = isResizable;
618     firePropertyChange("isResizable", old, this.isResizable);
619     }
620
621     /**
622      * Returns true if the user is allowed to resize the
623      * <code>TableColumn</code>'s
624      * width, false otherwise. You can change the width programmatically
625      * regardless of this setting. The default is true.
626      *
627      * @return the <code>isResizable</code> property
628      * @see #setResizable
629      */

630     public boolean getResizable() {
631     return isResizable;
632     }
633
634     /**
635      * Resizes the <code>TableColumn</code> to fit the width of its header cell.
636      * This method does nothing if the header renderer is <code>null</code>
637      * (the default case). Otherwise, it sets the minimum, maximum and preferred
638      * widths of this column to the widths of the minimum, maximum and preferred
639      * sizes of the Component delivered by the header renderer.
640      * The transient "width" property of this TableColumn is also set to the
641      * preferred width. Note this method is not used internally by the table
642      * package.
643      *
644      * @see #setPreferredWidth
645      */

646     public void sizeWidthToFit() {
647     if (headerRenderer == null) {
648         return;
649     }
650         Component JavaDoc c = headerRenderer.getTableCellRendererComponent(null,
651                 getHeaderValue(), false, false, 0, 0);
652
653     setMinWidth(c.getMinimumSize().width);
654     setMaxWidth(c.getMaximumSize().width);
655     setPreferredWidth(c.getPreferredSize().width);
656
657         setWidth(getPreferredWidth());
658     }
659
660     /**
661      * This field was not used in previous releases and there are
662      * currently no plans to support it in the future.
663      *
664      * @deprecated as of Java 2 platform v1.3
665      */

666     @Deprecated JavaDoc
667     public void disableResizedPosting() {
668     resizedPostingDisableCount++;
669     }
670
671     /**
672      * This field was not used in previous releases and there are
673      * currently no plans to support it in the future.
674      *
675      * @deprecated as of Java 2 platform v1.3
676      */

677     @Deprecated JavaDoc
678     public void enableResizedPosting() {
679     resizedPostingDisableCount--;
680     }
681
682 //
683
// Property Change Support
684
//
685

686     /**
687      * Adds a <code>PropertyChangeListener</code> to the listener list.
688      * The listener is registered for all properties.
689      * <p>
690      * A <code>PropertyChangeEvent</code> will get fired in response to an
691      * explicit call to <code>setFont</code>, <code>setBackground</code>,
692      * or <code>setForeground</code> on the
693      * current component. Note that if the current component is
694      * inheriting its foreground, background, or font from its
695      * container, then no event will be fired in response to a
696      * change in the inherited property.
697      *
698      * @param listener the listener to be added
699      *
700      */

701     public synchronized void addPropertyChangeListener(
702                                 PropertyChangeListener JavaDoc listener) {
703         if (changeSupport == null) {
704             changeSupport = new SwingPropertyChangeSupport JavaDoc(this);
705         }
706         changeSupport.addPropertyChangeListener(listener);
707     }
708
709     /**
710      * Removes a <code>PropertyChangeListener</code> from the listener list.
711      * The <code>PropertyChangeListener</code> to be removed was registered
712      * for all properties.
713      *
714      * @param listener the listener to be removed
715      *
716      */

717
718     public synchronized void removePropertyChangeListener(
719                                 PropertyChangeListener JavaDoc listener) {
720         if (changeSupport != null) {
721         changeSupport.removePropertyChangeListener(listener);
722     }
723     }
724
725     /**
726      * Returns an array of all the <code>PropertyChangeListener</code>s added
727      * to this TableColumn with addPropertyChangeListener().
728      *
729      * @return all of the <code>PropertyChangeListener</code>s added or an empty
730      * array if no listeners have been added
731      * @since 1.4
732      */

733     public synchronized PropertyChangeListener JavaDoc[] getPropertyChangeListeners() {
734         if (changeSupport == null) {
735             return new PropertyChangeListener JavaDoc[0];
736         }
737         return changeSupport.getPropertyChangeListeners();
738     }
739
740 //
741
// Protected Methods
742
//
743

744     /**
745      * As of Java 2 platform v1.3, this method is not called by the <code>TableColumn</code>
746      * constructor. Previously this method was used by the
747      * <code>TableColumn</code> to create a default header renderer.
748      * As of Java 2 platform v1.3, the default header renderer is <code>null</code>.
749      * <code>JTableHeader</code> now provides its own shared default
750      * renderer, just as the <code>JTable</code> does for its cell renderers.
751      *
752      * @return the default header renderer
753      * @see javax.swing.table.JTableHeader#createDefaultRenderer()
754      */

755     protected TableCellRenderer JavaDoc createDefaultHeaderRenderer() {
756     DefaultTableCellRenderer JavaDoc label = new DefaultTableCellRenderer JavaDoc() {
757         public Component JavaDoc getTableCellRendererComponent(JTable table, Object JavaDoc value,
758                          boolean isSelected, boolean hasFocus, int row, int column) {
759             if (table != null) {
760                 JTableHeader JavaDoc header = table.getTableHeader();
761                 if (header != null) {
762                     setForeground(header.getForeground());
763                     setBackground(header.getBackground());
764                     setFont(header.getFont());
765                 }
766                 }
767
768                 setText((value == null) ? "" : value.toString());
769         setBorder(UIManager.getBorder("TableHeader.cellBorder"));
770             return this;
771             }
772     };
773     label.setHorizontalAlignment(JLabel.CENTER);
774     return label;
775     }
776
777 } // End of class TableColumn
778

779
780
781
782
783
Popular Tags