* @param width the new width * @see #getWidth * @see #setMinWidth * @see #setMaxWidth * @see #setPreferredWidth * @see JTable#doLayout() * @beaninfo * bound: true * description: The width of the column. */ public void setWidth(int width) { int old = this.width; this.width = Math.min(Math.max(width, minWidth), maxWidth); firePropertyChange("width", old, this.width); } /** * Returns the width of the <code>TableColumn</code>. The default width is * 75. * * @return the <code>width</code> property * @see #setWidth */ public int getWidth() { return width; } /** * Sets this column's preferred width to <code>preferredWidth</code>. * If <code>preferredWidth</code> exceeds the minimum or maximum width, * it is adjusted to the appropriate limiting value. * <p> * For details on how the widths of columns in the <code>JTable</code> * (and <code>JTableHeader</code>) are calculated from the * <code>preferredWidth</code>, * see the <code>doLayout</code> method in <code>JTable</code>. * * @param preferredWidth the new preferred width * @see #getPreferredWidth * @see JTable#doLayout() * @beaninfo * bound: true * description: The preferred width of the column. */ public void setPreferredWidth(int preferredWidth) { int old = this.preferredWidth; this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth); firePropertyChange("preferredWidth", old, this.preferredWidth); } /** * Returns the preferred width of the <code>TableColumn</code>. * The default preferred width is 75. * * @return the <code>preferredWidth</code> property * @see #setPreferredWidth */ public int getPreferredWidth() { return preferredWidth; } /** * Sets the <code>TableColumn</code>'s minimum width to * <code>minWidth</code>, * adjusting the new minimum width if necessary to ensure that * 0 <= <code>minWidth</code> <= <code>maxWidth</code>. * For example, if the <code>minWidth</code> argument is negative, * this method sets the <code>minWidth</code> property to 0. * * <p> * If the value of the * <code>width</code> or <code>preferredWidth</code> property * is less than the new minimum width, * this method sets that property to the new minimum width. * * @param minWidth the new minimum width * @see #getMinWidth * @see #setPreferredWidth * @see #setMaxWidth * @beaninfo * bound: true * description: The minimum width of the column. */ public void setMinWidth(int minWidth) { int old = this.minWidth; this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0); if (width < this.minWidth) { setWidth(this.minWidth); } if (preferredWidth < this.minWidth) { setPreferredWidth(this.minWidth); } firePropertyChange("minWidth", old, this.minWidth); } /** * Returns the minimum width for the <code>TableColumn</code>. The * <code>TableColumn</code>'s width can't be made less than this either * by the user or programmatically. * * @return the <code>minWidth</code> property * @see #setMinWidth * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor) */ public int getMinWidth() { return minWidth; } /** * Sets the <code>TableColumn</code>'s maximum width to * <code>maxWidth</code> or, * if <code>maxWidth</code> is less than the minimum width, * to the minimum width. * * <p> * If the value of the * <code>width</code> or <code>preferredWidth</code> property * is more than the new maximum width, * this method sets that property to the new maximum width. * * @param maxWidth the new maximum width * @see #getMaxWidth * @see #setPreferredWidth * @see #setMinWidth * @beaninfo * bound: true * description: The maximum width of the column. */ public void setMaxWidth(int maxWidth) { int old = this.maxWidth; this.maxWidth = Math.max(minWidth, maxWidth); if (width > this.maxWidth) { setWidth(this.maxWidth); } if (preferredWidth > this.maxWidth) { setPreferredWidth(this.maxWidth); } firePropertyChange("maxWidth", old, this.maxWidth); } /** * Returns the maximum width for the <code>TableColumn</code>. The * <code>TableColumn</code>'s width can't be made larger than this * either by the user or programmatically. The default maxWidth * is Integer.MAX_VALUE. * * @return the <code>maxWidth</code> property * @see #setMaxWidth */ public int getMaxWidth() { return maxWidth; } /** * Sets whether this column can be resized. * * @param isResizable if true, resizing is allowed; otherwise false * @see #getResizable * @beaninfo * bound: true * description: Whether or not this column can be resized. */ public void setResizable(boolean isResizable) { boolean old = this.isResizable; this.isResizable = isResizable; firePropertyChange("isResizable", old, this.isResizable); } /** * Returns true if the user is allowed to resize the * <code>TableColumn</code>'s * width, false otherwise. You can change the width programmatically * regardless of this setting. The default is true. * * @return the <code>isResizable</code> property * @see #setResizable */ public boolean getResizable() { return isResizable; } /** * Resizes the <code>TableColumn</code> to fit the width of its header cell. * This method does nothing if the header renderer is <code>null</code> * (the default case). Otherwise, it sets the minimum, maximum and preferred * widths of this column to the widths of the minimum, maximum and preferred * sizes of the Component delivered by the header renderer. * The transient "width" property of this TableColumn is also set to the * preferred width. Note this method is not used internally by the table * package. * * @see #setPreferredWidth */ public void sizeWidthToFit() { if (headerRenderer == null) { return; } Component c = headerRenderer.getTableCellRendererComponent(null, getHeaderValue(), false, false, 0, 0); setMinWidth(c.getMinimumSize().width); setMaxWidth(c.getMaximumSize().width); setPreferredWidth(c.getPreferredSize().width); setWidth(getPreferredWidth()); } /** * This field was not used in previous releases and there are * currently no plans to support it in the future. * * @deprecated as of Java 2 platform v1.3 */ @Deprecated public void disableResizedPosting() { resizedPostingDisableCount++; } /** * This field was not used in previous releases and there are * currently no plans to support it in the future. * * @deprecated as of Java 2 platform v1.3 */ @Deprecated public void enableResizedPosting() { resizedPostingDisableCount--; } //// Property Change Support// /** * Adds a <code>PropertyChangeListener</code> to the listener list. * The listener is registered for all properties. * <p> * A <code>PropertyChangeEvent</code> will get fired in response to an * explicit call to <code>setFont</code>, <code>setBackground</code>, * or <code>setForeground</code> on the * current component. Note that if the current component is * inheriting its foreground, background, or font from its * container, then no event will be fired in response to a * change in the inherited property. * * @param listener the listener to be added * */ public synchronized void addPropertyChangeListener( PropertyChangeListener listener) { if (changeSupport == null) { changeSupport = new SwingPropertyChangeSupport(this); } changeSupport.addPropertyChangeListener(listener); } /** * Removes a <code>PropertyChangeListener</code> from the listener list. * The <code>PropertyChangeListener</code> to be removed was registered * for all properties. * * @param listener the listener to be removed * */ public synchronized void removePropertyChangeListener( PropertyChangeListener listener) { if (changeSupport != null) { changeSupport.removePropertyChangeListener(listener); } } /** * Returns an array of all the <code>PropertyChangeListener</code>s added * to this TableColumn with addPropertyChangeListener(). * * @return all of the <code>PropertyChangeListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public synchronized PropertyChangeListener[] getPropertyChangeListeners() { if (changeSupport == null) { return new PropertyChangeListener[0]; } return changeSupport.getPropertyChangeListeners(); } //// Protected Methods// /** * As of Java 2 platform v1.3, this method is not called by the <code>TableColumn</code> * constructor. Previously this method was used by the * <code>TableColumn</code> to create a default header renderer. * As of Java 2 platform v1.3, the default header renderer is <code>null</code>. * <code>JTableHeader</code> now provides its own shared default * renderer, just as the <code>JTable</code> does for its cell renderers. * * @return the default header renderer * @see javax.swing.table.JTableHeader#createDefaultRenderer() */ protected TableCellRenderer createDefaultHeaderRenderer() { DefaultTableCellRenderer label = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; } }; label.setHorizontalAlignment(JLabel.CENTER); return label; } } // End of class TableColumnLines 501–825 of 825. Previous lines
* @param width the new width * @see #getWidth * @see #setMinWidth * @see #setMaxWidth * @see #setPreferredWidth * @see JTable#doLayout() * @beaninfo * bound: true * description: The width of the column. */ public void setWidth(int width) { int old = this.width; this.width = Math.min(Math.max(width, minWidth), maxWidth); firePropertyChange("width", old, this.width); } /** * Returns the width of the <code>TableColumn</code>. The default width is * 75. * * @return the <code>width</code> property * @see #setWidth */ public int getWidth() { return width; } /** * Sets this column's preferred width to <code>preferredWidth</code>. * If <code>preferredWidth</code> exceeds the minimum or maximum width, * it is adjusted to the appropriate limiting value. * <p> * For details on how the widths of columns in the <code>JTable</code> * (and <code>JTableHeader</code>) are calculated from the * <code>preferredWidth</code>, * see the <code>doLayout</code> method in <code>JTable</code>. * * @param preferredWidth the new preferred width * @see #getPreferredWidth * @see JTable#doLayout() * @beaninfo * bound: true * description: The preferred width of the column. */ public void setPreferredWidth(int preferredWidth) { int old = this.preferredWidth; this.preferredWidth = Math.min(Math.max(preferredWidth, minWidth), maxWidth); firePropertyChange("preferredWidth", old, this.preferredWidth); } /** * Returns the preferred width of the <code>TableColumn</code>. * The default preferred width is 75. * * @return the <code>preferredWidth</code> property * @see #setPreferredWidth */ public int getPreferredWidth() { return preferredWidth; } /** * Sets the <code>TableColumn</code>'s minimum width to * <code>minWidth</code>, * adjusting the new minimum width if necessary to ensure that * 0 <= <code>minWidth</code> <= <code>maxWidth</code>. * For example, if the <code>minWidth</code> argument is negative, * this method sets the <code>minWidth</code> property to 0. * * <p> * If the value of the * <code>width</code> or <code>preferredWidth</code> property * is less than the new minimum width, * this method sets that property to the new minimum width. * * @param minWidth the new minimum width * @see #getMinWidth * @see #setPreferredWidth * @see #setMaxWidth * @beaninfo * bound: true * description: The minimum width of the column. */ public void setMinWidth(int minWidth) { int old = this.minWidth; this.minWidth = Math.max(Math.min(minWidth, maxWidth), 0); if (width < this.minWidth) { setWidth(this.minWidth); } if (preferredWidth < this.minWidth) { setPreferredWidth(this.minWidth); } firePropertyChange("minWidth", old, this.minWidth); } /** * Returns the minimum width for the <code>TableColumn</code>. The * <code>TableColumn</code>'s width can't be made less than this either * by the user or programmatically. * * @return the <code>minWidth</code> property * @see #setMinWidth * @see #TableColumn(int, int, TableCellRenderer, TableCellEditor) */ public int getMinWidth() { return minWidth; } /** * Sets the <code>TableColumn</code>'s maximum width to * <code>maxWidth</code> or, * if <code>maxWidth</code> is less than the minimum width, * to the minimum width. * * <p> * If the value of the * <code>width</code> or <code>preferredWidth</code> property * is more than the new maximum width, * this method sets that property to the new maximum width. * * @param maxWidth the new maximum width * @see #getMaxWidth * @see #setPreferredWidth * @see #setMinWidth * @beaninfo * bound: true * description: The maximum width of the column. */ public void setMaxWidth(int maxWidth) { int old = this.maxWidth; this.maxWidth = Math.max(minWidth, maxWidth); if (width > this.maxWidth) { setWidth(this.maxWidth); } if (preferredWidth > this.maxWidth) { setPreferredWidth(this.maxWidth); } firePropertyChange("maxWidth", old, this.maxWidth); } /** * Returns the maximum width for the <code>TableColumn</code>. The * <code>TableColumn</code>'s width can't be made larger than this * either by the user or programmatically. The default maxWidth * is Integer.MAX_VALUE. * * @return the <code>maxWidth</code> property * @see #setMaxWidth */ public int getMaxWidth() { return maxWidth; } /** * Sets whether this column can be resized. * * @param isResizable if true, resizing is allowed; otherwise false * @see #getResizable * @beaninfo * bound: true * description: Whether or not this column can be resized. */ public void setResizable(boolean isResizable) { boolean old = this.isResizable; this.isResizable = isResizable; firePropertyChange("isResizable", old, this.isResizable); } /** * Returns true if the user is allowed to resize the * <code>TableColumn</code>'s * width, false otherwise. You can change the width programmatically * regardless of this setting. The default is true. * * @return the <code>isResizable</code> property * @see #setResizable */ public boolean getResizable() { return isResizable; } /** * Resizes the <code>TableColumn</code> to fit the width of its header cell. * This method does nothing if the header renderer is <code>null</code> * (the default case). Otherwise, it sets the minimum, maximum and preferred * widths of this column to the widths of the minimum, maximum and preferred * sizes of the Component delivered by the header renderer. * The transient "width" property of this TableColumn is also set to the * preferred width. Note this method is not used internally by the table * package. * * @see #setPreferredWidth */ public void sizeWidthToFit() { if (headerRenderer == null) { return; } Component c = headerRenderer.getTableCellRendererComponent(null, getHeaderValue(), false, false, 0, 0); setMinWidth(c.getMinimumSize().width); setMaxWidth(c.getMaximumSize().width); setPreferredWidth(c.getPreferredSize().width); setWidth(getPreferredWidth()); } /** * This field was not used in previous releases and there are * currently no plans to support it in the future. * * @deprecated as of Java 2 platform v1.3 */ @Deprecated public void disableResizedPosting() { resizedPostingDisableCount++; } /** * This field was not used in previous releases and there are * currently no plans to support it in the future. * * @deprecated as of Java 2 platform v1.3 */ @Deprecated public void enableResizedPosting() { resizedPostingDisableCount--; } // // Property Change Support // /** * Adds a <code>PropertyChangeListener</code> to the listener list. * The listener is registered for all properties. * <p> * A <code>PropertyChangeEvent</code> will get fired in response to an * explicit call to <code>setFont</code>, <code>setBackground</code>, * or <code>setForeground</code> on the * current component. Note that if the current component is * inheriting its foreground, background, or font from its * container, then no event will be fired in response to a * change in the inherited property. * * @param listener the listener to be added * */ public synchronized void addPropertyChangeListener( PropertyChangeListener listener) { if (changeSupport == null) { changeSupport = new SwingPropertyChangeSupport(this); } changeSupport.addPropertyChangeListener(listener); } /** * Removes a <code>PropertyChangeListener</code> from the listener list. * The <code>PropertyChangeListener</code> to be removed was registered * for all properties. * * @param listener the listener to be removed * */ public synchronized void removePropertyChangeListener( PropertyChangeListener listener) { if (changeSupport != null) { changeSupport.removePropertyChangeListener(listener); } } /** * Returns an array of all the <code>PropertyChangeListener</code>s added * to this TableColumn with addPropertyChangeListener(). * * @return all of the <code>PropertyChangeListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public synchronized PropertyChangeListener[] getPropertyChangeListeners() { if (changeSupport == null) { return new PropertyChangeListener[0]; } return changeSupport.getPropertyChangeListeners(); } // // Protected Methods // /** * As of Java 2 platform v1.3, this method is not called by the <code>TableColumn</code> * constructor. Previously this method was used by the * <code>TableColumn</code> to create a default header renderer. * As of Java 2 platform v1.3, the default header renderer is <code>null</code>. * <code>JTableHeader</code> now provides its own shared default * renderer, just as the <code>JTable</code> does for its cell renderers. * * @return the default header renderer * @see javax.swing.table.JTableHeader#createDefaultRenderer() */ protected TableCellRenderer createDefaultHeaderRenderer() { DefaultTableCellRenderer label = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { setForeground(header.getForeground()); setBackground(header.getBackground()); setFont(header.getFont()); } } setText((value == null) ? "" : value.toString()); setBorder(UIManager.getBorder("TableHeader.cellBorder")); return this; } }; label.setHorizontalAlignment(JLabel.CENTER); return label; } } // End of class TableColumn