- java.lang.Object
-
- javax.swing.table.DefaultTableColumnModel
-
- All Implemented Interfaces:
-
PropertyChangeListener,Serializable,EventListener,ListSelectionListener,TableColumnModel
public class DefaultTableColumnModel extends Object implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable
JTable的标准列处理程序。警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,支持所有JavaBeans的长期存储已被添加到
java.beans包中。 请参阅XMLEncoder。- 另请参见:
-
JTable, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field 描述 protected ChangeEventchangeEvent更改事件(只需一个)protected intcolumnMargin每列之间的宽度protected booleancolumnSelectionAllowed此列模型允许列选择protected EventListenerListlistenerListTableColumnModelListener列表protected ListSelectionModelselectionModel跟踪列选择的模型protected Vector<TableColumn>tableColumns此模型中的TableColumn对象数组protected inttotalColumnWidth所有列的组合宽度的本地缓存
-
构造方法摘要
构造方法 Constructor 描述 DefaultTableColumnModel()创建默认表列模型。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidaddColumn(TableColumn aColumn)追加aColumn到tableColumns阵列的末尾。voidaddColumnModelListener(TableColumnModelListener x)为表格列模型事件添加一个侦听器。protected ListSelectionModelcreateSelectionModel()创建一个新的默认列表选择模型。protected voidfireColumnAdded(TableColumnModelEvent e)通知所有在此事件类型上通知有兴趣的听众。protected voidfireColumnMarginChanged()通知所有在此事件类型上通知有兴趣的听众。protected voidfireColumnMoved(TableColumnModelEvent e)通知所有在此事件类型上通知有兴趣的听众。protected voidfireColumnRemoved(TableColumnModelEvent e)通知所有在此事件类型上通知有兴趣的听众。protected voidfireColumnSelectionChanged(ListSelectionEvent e)通知所有在此事件类型上通知有兴趣的听众。TableColumngetColumn(int columnIndex)返回TableColumn在列对象columnIndex。intgetColumnCount()返回tableColumns数组中的列数。intgetColumnIndex(Object identifier)当使用equals进行比较时,返回tableColumns阵列中其标识符等于identifier的第一列的索引。intgetColumnIndexAtX(int x)返回位于x的列的索引,如果没有列覆盖此点,则返回-1。intgetColumnMargin()返回TableColumn的宽度。TableColumnModelListener[]getColumnModelListeners()返回在此模型上注册的所有列模型侦听器的数组。Enumeration<TableColumn>getColumns()返回Enumeration中所有列的Enumeration。booleangetColumnSelectionAllowed()如果允许列选择,则返回true,否则返回false。<T extends EventListener>
T[]getListeners(Class<T> listenerType)返回此模型上当前注册为FooListener的所有对象的数组。intgetSelectedColumnCount()返回所选列数。int[]getSelectedColumns()返回所选列的数组。ListSelectionModelgetSelectionModel()返回用于维护列选择状态的ListSelectionModel。intgetTotalColumnWidth()返回所有列的总合并宽度。voidmoveColumn(int columnIndex, int newIndex)将列和标题从columnIndex移动到newIndex。voidpropertyChange(PropertyChangeEvent evt)属性更改侦听器更改方法。protected voidrecalcWidthCache()重新计算所有列的总合并宽度。voidremoveColumn(TableColumn column)删除column从tableColumns阵列。voidremoveColumnModelListener(TableColumnModelListener x)删除表列模型事件的侦听器。voidsetColumnMargin(int newMargin)将列边距设置为newMargin。voidsetColumnSelectionAllowed(boolean flag)设置是否允许列选择。voidsetSelectionModel(ListSelectionModel newModel)设置此选择模型TableColumnModel至newModel并注册为来自新选择模型的通知。voidvalueChanged(ListSelectionEvent e)AListSelectionListener当有列选择更改时转发ListSelectionEvents。
-
-
-
字段详细信息
-
tableColumns
protected Vector<TableColumn> tableColumns
此模型中的TableColumn对象数组
-
selectionModel
protected ListSelectionModel selectionModel
跟踪列选择的模型
-
columnMargin
protected int columnMargin
每列之间的宽度
-
listenerList
protected EventListenerList listenerList
TableColumnModelListener列表
-
changeEvent
protected transient ChangeEvent changeEvent
更改事件(只需一个)
-
columnSelectionAllowed
protected boolean columnSelectionAllowed
此列模型允许列选择
-
totalColumnWidth
protected int totalColumnWidth
所有列的组合宽度的本地缓存
-
-
方法详细信息
-
addColumn
public void addColumn(TableColumn aColumn)
将aColumn追加到tableColumns阵列的末尾。 该方法也将columnAdded事件发布到其监听器。- Specified by:
-
addColumn在接口TableColumnModel - 参数
-
aColumn- 要添加的TableColumn - 异常
-
IllegalArgumentException- 如果aColumn是null - 另请参见:
-
removeColumn(javax.swing.table.TableColumn)
-
removeColumn
public void removeColumn(TableColumn column)
删除column从tableColumns阵列。 如果column不在表的列列表中,此方法将column。tile来调整头和表视图的大小。 这种方法也会向其听众发布一个columnRemoved事件。- Specified by:
-
removeColumn在接口TableColumnModel - 参数
-
column- 要删除的TableColumn - 另请参见:
-
addColumn(javax.swing.table.TableColumn)
-
moveColumn
public void moveColumn(int columnIndex, int newIndex)将列和标题从columnIndex移动到newIndex。 在旧列columnIndex现在被发现在newIndex。 以前在newIndex的列向左或向右移动以腾出空间。 如果columnIndex等于newIndex则不会移动任何列。 此方法也会向其收听者发布一个columnMoved事件。- Specified by:
-
moveColumn在接口TableColumnModel - 参数
-
columnIndex- 要移动的列的索引 -
newIndex- 移动列的新索引 - 异常
-
IllegalArgumentException- 如果column或newIndex不在有效范围内
-
setColumnMargin
public void setColumnMargin(int newMargin)
将列边距设置为newMargin。 这个方法也会向其听众发送一个columnMarginChanged事件。- Specified by:
-
setColumnMargin接口TableColumnModel - 参数
-
newMargin- 新的边距宽度,以像素为单位 - 另请参见:
-
getColumnMargin(),getTotalColumnWidth()
-
getColumnCount
public int getColumnCount()
返回tableColumns数组中的列数。- Specified by:
-
getColumnCount在接口TableColumnModel - 结果
-
tableColumns数组中的列数 - 另请参见:
-
getColumns()
-
getColumns
public Enumeration<TableColumn> getColumns()
返回Enumeration中所有列的Enumeration。- Specified by:
-
getColumns在接口TableColumnModel - 结果
-
一个
Enumeration的列中的模型
-
getColumnIndex
public int getColumnIndex(Object identifier)
当使用equals进行比较时,返回tableColumns数组中的标识符等于identifier的第一列的索引。- Specified by:
-
getColumnIndex在接口TableColumnModel - 参数
-
identifier- 标识符对象 - 结果
-
tableColumns阵列中第一列的标识符等于identifier - 异常
-
IllegalArgumentException- 如果identifier是null,或者如果没有TableColumn有这个identifier - 另请参见:
-
getColumn(int)
-
getColumn
public TableColumn getColumn(int columnIndex)
返回TableColumn在列对象columnIndex。- Specified by:
-
getColumn接口TableColumnModel - 参数
-
columnIndex- 所需列的索引 - 结果
-
该列的
TableColumn对象为columnIndex
-
getColumnMargin
public int getColumnMargin()
返回TableColumn的宽度。 默认columnMargin为1。- Specified by:
-
getColumnMargin在接口TableColumnModel - 结果
-
最大宽度为
TableColumn - 另请参见:
-
setColumnMargin(int)
-
getColumnIndexAtX
public int getColumnIndexAtX(int x)
返回位于x的列的索引,如果没有列覆盖此点,则返回-1。 与Swing的可分离模型架构保持一致,TableColumnModel不知道表列如何在屏幕上实际显示。 列的视觉呈现是使用此模型(通常为JTable)的视图/控制器对象的责任。 视图/控制器不需要从左到右依次显示列。 例如,可以从右到左显示列,以容纳区域设置首选项,或者可能在用户的请求下隐藏某些列。 因为模型不知道列如何布置在屏幕上,所以给定的xPosition不应该被认为是2D图形空间中的坐标。 相反,它应该被认为是从模型中第一列开始的宽度。 如果需要2D空间中给定X坐标的列索引,JTable.columnAtPoint可以使用JTable.columnAtPoint。- Specified by:
-
getColumnIndexAtX在接口TableColumnModel - 参数
-
x- 感兴趣的水平位置 - 结果
- 列的索引,如果没有列,则为-1
- 另请参见:
-
JTable.columnAtPoint(java.awt.Point)
-
getTotalColumnWidth
public int getTotalColumnWidth()
返回所有列的总合并宽度。- Specified by:
-
getTotalColumnWidth在接口TableColumnModel - 结果
-
totalColumnWidth属性
-
setSelectionModel
public void setSelectionModel(ListSelectionModel newModel)
设置此选择模型TableColumnModel至newModel并注册为来自新选择模型的通知。 如果newModel为null,则抛出异常。- Specified by:
-
setSelectionModel在接口TableColumnModel - 参数
-
newModel- 新的选择模式 - 异常
-
IllegalArgumentException- 如果newModel是null - 另请参见:
-
getSelectionModel()
-
getSelectionModel
public ListSelectionModel getSelectionModel()
返回用于维护列选择状态的ListSelectionModel。- Specified by:
-
getSelectionModel在接口TableColumnModel - 结果
-
提供列选择状态的对象。
或者如果不允许行选择,则为
null。 - 另请参见:
-
setSelectionModel(javax.swing.ListSelectionModel)
-
setColumnSelectionAllowed
public void setColumnSelectionAllowed(boolean flag)
设置是否允许列选择。 默认值为false。- Specified by:
-
setColumnSelectionAllowed在接口TableColumnModel - 参数
-
flag- 如果允许列选择,flagtrue,否则为false - 另请参见:
-
TableColumnModel.getColumnSelectionAllowed()
-
getColumnSelectionAllowed
public boolean getColumnSelectionAllowed()
如果允许列选择,则返回true,否则返回false。 默认值为false。- Specified by:
-
getColumnSelectionAllowed在接口TableColumnModel - 结果
-
columnSelectionAllowed属性 - 另请参见:
-
TableColumnModel.setColumnSelectionAllowed(boolean)
-
getSelectedColumns
public int[] getSelectedColumns()
返回所选列的数组。 如果selectionModel为null,则返回一个空数组。- Specified by:
-
getSelectedColumns在接口TableColumnModel - 结果
-
所选列的数组或空数组,如果没有选择,或
selectionModel是null
-
getSelectedColumnCount
public int getSelectedColumnCount()
返回所选列数。- Specified by:
-
getSelectedColumnCount在接口TableColumnModel - 结果
- 选择的列数
-
addColumnModelListener
public void addColumnModelListener(TableColumnModelListener x)
为表格列模型事件添加一个侦听器。- Specified by:
-
addColumnModelListener在接口TableColumnModel - 参数
-
x- 一个TableColumnModelListener对象
-
removeColumnModelListener
public void removeColumnModelListener(TableColumnModelListener x)
删除表列模型事件的侦听器。- Specified by:
-
removeColumnModelListener在接口TableColumnModel - 参数
-
x- 一个TableColumnModelListener对象
-
getColumnModelListeners
public TableColumnModelListener[] getColumnModelListeners()
返回在此模型上注册的所有列模型侦听器的数组。- 结果
-
所有这个默认表列模型的
ColumnModelListeners或一个空数组,如果没有列模型侦听器当前注册 - 从以下版本开始:
- 1.4
- 另请参见:
-
addColumnModelListener(javax.swing.event.TableColumnModelListener),removeColumnModelListener(javax.swing.event.TableColumnModelListener)
-
fireColumnAdded
protected void fireColumnAdded(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 参数
-
e- 收到的事件 - 另请参见:
-
EventListenerList
-
fireColumnRemoved
protected void fireColumnRemoved(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 参数
-
e- 收到的事件 - 另请参见:
-
EventListenerList
-
fireColumnMoved
protected void fireColumnMoved(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 参数
-
e- 收到的事件 - 另请参见:
-
EventListenerList
-
fireColumnSelectionChanged
protected void fireColumnSelectionChanged(ListSelectionEvent e)
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 参数
-
e- 收到的事件 - 另请参见:
-
EventListenerList
-
fireColumnMarginChanged
protected void fireColumnMarginChanged()
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 另请参见:
-
EventListenerList
-
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
返回当前注册为FooListener的所有对象的数组。FooListener使用addFooListener方法注册。您可以使用类文字指定
listenerType参数,如FooListener.class。 例如,您可以使用以下代码查询DefaultTableColumnModelm其列模型侦听器:ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));如果没有这样的侦听器存在,这个方法返回一个空数组。- 参数类型
-
T- 侦听器类型 - 参数
-
listenerType- 所请求的听众的类型 - 结果
-
在此模型上注册为
FooListeners的所有对象的数组,如果没有添加此类侦听器,则为空数组 - 异常
-
ClassCastException- 如果listenerType没有指定实现java.util.EventListener的类或接口 - 从以下版本开始:
- 1.3
- 另请参见:
-
getColumnModelListeners()
-
propertyChange
public void propertyChange(PropertyChangeEvent evt)
属性更改侦听器更改方法。 用于跟踪列宽或首选列宽度的更改。- Specified by:
-
propertyChange在接口PropertyChangeListener - 参数
-
evt-PropertyChangeEvent
-
valueChanged
public void valueChanged(ListSelectionEvent e)
AListSelectionListener,当有列选择更改时,转发ListSelectionEvents。- Specified by:
-
valueChanged在接口ListSelectionListener - 参数
-
e- 变更事件
-
createSelectionModel
protected ListSelectionModel createSelectionModel()
创建一个新的默认列表选择模型。- 结果
- 一个新创建的默认列表选择模型。
-
recalcWidthCache
protected void recalcWidthCache()
重新计算所有列的总合并宽度。 更新totalColumnWidth属性。
-
-