Methods Summary |
---|
public void | addColumn(javax.swing.table.TableColumn aColumn)Appends aColumn to the end of the
tableColumns array.
This method also posts the columnAdded
event to its listeners.
if (aColumn == null) {
throw new IllegalArgumentException("Object is null");
}
tableColumns.addElement(aColumn);
aColumn.addPropertyChangeListener(this);
invalidateWidthCache();
// Post columnAdded event notification
fireColumnAdded(new TableColumnModelEvent(this, 0,
getColumnCount() - 1));
|
public void | addColumnModelListener(javax.swing.event.TableColumnModelListener x)Adds a listener for table column model events.
listenerList.add(TableColumnModelListener.class, x);
|
protected javax.swing.ListSelectionModel | createSelectionModel()Creates a new default list selection model.
return new DefaultListSelectionModel();
|
protected void | fireColumnAdded(javax.swing.event.TableColumnModelEvent e)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TableColumnModelListener.class) {
// Lazily create the event:
// if (e == null)
// e = new ChangeEvent(this);
((TableColumnModelListener)listeners[i+1]).
columnAdded(e);
}
}
|
protected void | fireColumnMarginChanged()Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TableColumnModelListener.class) {
// Lazily create the event:
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
((TableColumnModelListener)listeners[i+1]).
columnMarginChanged(changeEvent);
}
}
|
protected void | fireColumnMoved(javax.swing.event.TableColumnModelEvent e)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TableColumnModelListener.class) {
// Lazily create the event:
// if (e == null)
// e = new ChangeEvent(this);
((TableColumnModelListener)listeners[i+1]).
columnMoved(e);
}
}
|
protected void | fireColumnRemoved(javax.swing.event.TableColumnModelEvent e)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TableColumnModelListener.class) {
// Lazily create the event:
// if (e == null)
// e = new ChangeEvent(this);
((TableColumnModelListener)listeners[i+1]).
columnRemoved(e);
}
}
|
protected void | fireColumnSelectionChanged(javax.swing.event.ListSelectionEvent e)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TableColumnModelListener.class) {
// Lazily create the event:
// if (e == null)
// e = new ChangeEvent(this);
((TableColumnModelListener)listeners[i+1]).
columnSelectionChanged(e);
}
}
|
public javax.swing.table.TableColumn | getColumn(int columnIndex)Returns the TableColumn object for the column
at columnIndex .
return (TableColumn)tableColumns.elementAt(columnIndex);
|
public int | getColumnCount()Returns the number of columns in the tableColumns array.
return tableColumns.size();
|
public int | getColumnIndex(java.lang.Object identifier)Returns the index of the first column in the tableColumns
array whose identifier is equal to identifier ,
when compared using equals .
if (identifier == null) {
throw new IllegalArgumentException("Identifier is null");
}
Enumeration enumeration = getColumns();
TableColumn aColumn;
int index = 0;
while (enumeration.hasMoreElements()) {
aColumn = (TableColumn)enumeration.nextElement();
// Compare them this way in case the column's identifier is null.
if (identifier.equals(aColumn.getIdentifier()))
return index;
index++;
}
throw new IllegalArgumentException("Identifier not found");
|
public int | getColumnIndexAtX(int x)Returns the index of the column that lies at position x ,
or -1 if no column covers this point.
In keeping with Swing's separable model architecture, a
TableColumnModel does not know how the table columns actually appear on
screen. The visual presentation of the columns is the responsibility
of the view/controller object using this model (typically JTable). The
view/controller need not display the columns sequentially from left to
right. For example, columns could be displayed from right to left to
accomodate a locale preference or some columns might be hidden at the
request of the user. Because the model does not know how the columns
are laid out on screen, the given xPosition should not be
considered to be a coordinate in 2D graphics space. Instead, it should
be considered to be a width from the start of the first column in the
model. If the column index for a given X coordinate in 2D space is
required, JTable.columnAtPoint can be used instead.
if (x < 0) {
return -1;
}
int cc = getColumnCount();
for(int column = 0; column < cc; column++) {
x = x - getColumn(column).getWidth();
if (x < 0) {
return column;
}
}
return -1;
|
public int | getColumnMargin()Returns the width margin for TableColumn .
The default columnMargin is 1.
return columnMargin;
|
public javax.swing.event.TableColumnModelListener[] | getColumnModelListeners()Returns an array of all the column model listeners
registered on this model.
return (TableColumnModelListener[])listenerList.getListeners(
TableColumnModelListener.class);
|
public boolean | getColumnSelectionAllowed()Returns true if column selection is allowed, otherwise false.
The default is false.
return columnSelectionAllowed;
|
public java.util.Enumeration | getColumns()Returns an Enumeration of all the columns in the model.
return tableColumns.elements();
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as FooListener s
upon this model.
FooListener s are registered using the
addFooListener method.
You can specify the listenerType argument
with a class literal,
such as
FooListener.class .
For example, you can query a
DefaultTableColumnModel m
for its column model listeners with the following code:
ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));
If no such listeners exist, this method returns an empty array.
return listenerList.getListeners(listenerType);
|
public int | getSelectedColumnCount()Returns the number of columns selected.
if (selectionModel != null) {
int iMin = selectionModel.getMinSelectionIndex();
int iMax = selectionModel.getMaxSelectionIndex();
int count = 0;
for(int i = iMin; i <= iMax; i++) {
if (selectionModel.isSelectedIndex(i)) {
count++;
}
}
return count;
}
return 0;
|
public int[] | getSelectedColumns()Returns an array of selected columns. If selectionModel
is null , returns an empty array.
if (selectionModel != null) {
int iMin = selectionModel.getMinSelectionIndex();
int iMax = selectionModel.getMaxSelectionIndex();
if ((iMin == -1) || (iMax == -1)) {
return new int[0];
}
int[] rvTmp = new int[1+ (iMax - iMin)];
int n = 0;
for(int i = iMin; i <= iMax; i++) {
if (selectionModel.isSelectedIndex(i)) {
rvTmp[n++] = i;
}
}
int[] rv = new int[n];
System.arraycopy(rvTmp, 0, rv, 0, n);
return rv;
}
return new int[0];
|
public javax.swing.ListSelectionModel | getSelectionModel()Returns the ListSelectionModel that is used to
maintain column selection state.
return selectionModel;
|
public int | getTotalColumnWidth()Returns the total combined width of all columns.
if (totalColumnWidth == -1) {
recalcWidthCache();
}
return totalColumnWidth;
|
private void | invalidateWidthCache()
totalColumnWidth = -1;
|
public void | moveColumn(int columnIndex, int newIndex)Moves the column and heading at columnIndex to
newIndex . The old column at columnIndex
will now be found at newIndex . The column
that used to be at newIndex is shifted
left or right to make room. This will not move any columns if
columnIndex equals newIndex . This method
also posts a columnMoved event to its listeners.
if ((columnIndex < 0) || (columnIndex >= getColumnCount()) ||
(newIndex < 0) || (newIndex >= getColumnCount()))
throw new IllegalArgumentException("moveColumn() - Index out of range");
TableColumn aColumn;
// If the column has not yet moved far enough to change positions
// post the event anyway, the "draggedDistance" property of the
// tableHeader will say how far the column has been dragged.
// Here we are really trying to get the best out of an
// API that could do with some rethinking. We preserve backward
// compatibility by slightly bending the meaning of these methods.
if (columnIndex == newIndex) {
fireColumnMoved(new TableColumnModelEvent(this, columnIndex, newIndex));
return;
}
aColumn = (TableColumn)tableColumns.elementAt(columnIndex);
tableColumns.removeElementAt(columnIndex);
boolean selected = selectionModel.isSelectedIndex(columnIndex);
selectionModel.removeIndexInterval(columnIndex,columnIndex);
tableColumns.insertElementAt(aColumn, newIndex);
selectionModel.insertIndexInterval(newIndex, 1, true);
if (selected) {
selectionModel.addSelectionInterval(newIndex, newIndex);
}
else {
selectionModel.removeSelectionInterval(newIndex, newIndex);
}
fireColumnMoved(new TableColumnModelEvent(this, columnIndex,
newIndex));
|
public void | propertyChange(java.beans.PropertyChangeEvent evt)Property Change Listener change method. Used to track changes
to the column width or preferred column width.
String name = evt.getPropertyName();
if (name == "width" || name == "preferredWidth") {
invalidateWidthCache();
// This is a misnomer, we're using this method
// simply to cause a relayout.
fireColumnMarginChanged();
}
|
protected void | recalcWidthCache()Recalculates the total combined width of all columns. Updates the
totalColumnWidth property.
Enumeration enumeration = getColumns();
totalColumnWidth = 0;
while (enumeration.hasMoreElements()) {
totalColumnWidth += ((TableColumn)enumeration.nextElement()).getWidth();
}
|
public void | removeColumn(javax.swing.table.TableColumn column)Deletes the column from the
tableColumns array. This method will do nothing if
column is not in the table's columns list.
tile is called
to resize both the header and table views.
This method also posts a columnRemoved
event to its listeners.
int columnIndex = tableColumns.indexOf(column);
if (columnIndex != -1) {
// Adjust for the selection
if (selectionModel != null) {
selectionModel.removeIndexInterval(columnIndex,columnIndex);
}
column.removePropertyChangeListener(this);
tableColumns.removeElementAt(columnIndex);
invalidateWidthCache();
// Post columnAdded event notification. (JTable and JTableHeader
// listens so they can adjust size and redraw)
fireColumnRemoved(new TableColumnModelEvent(this,
columnIndex, 0));
}
|
public void | removeColumnModelListener(javax.swing.event.TableColumnModelListener x)Removes a listener for table column model events.
listenerList.remove(TableColumnModelListener.class, x);
|
public void | setColumnMargin(int newMargin)Sets the column margin to newMargin . This method
also posts a columnMarginChanged event to its
listeners.
if (newMargin != columnMargin) {
columnMargin = newMargin;
// Post columnMarginChanged event notification.
fireColumnMarginChanged();
}
|
public void | setColumnSelectionAllowed(boolean flag)Sets whether column selection is allowed. The default is false.
columnSelectionAllowed = flag;
|
public void | setSelectionModel(javax.swing.ListSelectionModel newModel)Sets the selection model for this TableColumnModel
to newModel
and registers for listener notifications from the new selection
model. If newModel is null ,
an exception is thrown.
if (newModel == null) {
throw new IllegalArgumentException("Cannot set a null SelectionModel");
}
ListSelectionModel oldModel = selectionModel;
if (newModel != oldModel) {
if (oldModel != null) {
oldModel.removeListSelectionListener(this);
}
selectionModel= newModel;
newModel.addListSelectionListener(this);
}
|
public void | valueChanged(javax.swing.event.ListSelectionEvent e)A ListSelectionListener that forwards
ListSelectionEvents when there is a column
selection change.
fireColumnSelectionChanged(e);
|