public class DefaultTableColumnModel extends Object implements TableColumnModel, PropertyChangeListener, ListSelectionListener, Serializable
JTable的标准列处理程序。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
JTable
| Modifier and Type | Field and Description |
|---|---|
protected ChangeEvent |
changeEvent
更改事件(只需一个)
|
protected int |
columnMargin
每列之间的宽度
|
protected boolean |
columnSelectionAllowed
此列模型允许列选择
|
protected EventListenerList |
listenerList
TableColumnModelListener列表
|
protected ListSelectionModel |
selectionModel
跟踪列选择的模型
|
protected Vector<TableColumn> |
tableColumns
此模型中的TableColumn对象数组
|
protected int |
totalColumnWidth
所有列的组合宽度的本地缓存
|
| Constructor and Description |
|---|
DefaultTableColumnModel()
创建默认表列模型。
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumn(TableColumn aColumn)
将
aColumn追加到
tableColumns数组的末尾。
|
void |
addColumnModelListener(TableColumnModelListener x)
为表格列模型事件添加一个侦听器。
|
protected ListSelectionModel |
createSelectionModel()
创建一个新的默认列表选择模型。
|
protected void |
fireColumnAdded(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
protected void |
fireColumnMarginChanged()
通知所有在此事件类型上通知有兴趣的听众。
|
protected void |
fireColumnMoved(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
protected void |
fireColumnRemoved(TableColumnModelEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
protected void |
fireColumnSelectionChanged(ListSelectionEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
TableColumn |
getColumn(int columnIndex)
返回
TableColumn在列对象
columnIndex 。
|
int |
getColumnCount()
返回
tableColumns数组中的列数。
|
int |
getColumnIndex(Object identifier)
当使用
equals进行比较时,返回标识符等于
identifier的
tableColumns数组中第一列的索引。
|
int |
getColumnIndexAtX(int x)
返回位于
x位置的列的索引,如果没有列覆盖此点,则返回-1。
|
int |
getColumnMargin()
返回
TableColumn的宽度边距。
|
TableColumnModelListener[] |
getColumnModelListeners()
返回在此模型上注册的所有列模型侦听器的数组。
|
Enumeration<TableColumn> |
getColumns()
返回
Enumeration中所有列的
Enumeration 。
|
boolean |
getColumnSelectionAllowed()
如果允许列选择,则返回true,否则返回false。
|
<T extends EventListener> |
getListeners(类<T> listenerType)
返回此模型当前注册为
FooListener的所有对象的数组。
|
int |
getSelectedColumnCount()
返回所选列数。
|
int[] |
getSelectedColumns()
返回所选列的数组。
|
ListSelectionModel |
getSelectionModel()
返回
ListSelectionModel用来维护列选择状态。
|
int |
getTotalColumnWidth()
返回所有列的总合并宽度。
|
void |
moveColumn(int columnIndex, int newIndex)
将列和标题
columnIndex至
newIndex 。
|
void |
propertyChange(PropertyChangeEvent evt)
属性更改侦听器更改方法。
|
protected void |
recalcWidthCache()
重新计算所有列的总合并宽度。
|
void |
removeColumn(TableColumn column)
删除
column从
tableColumns阵列。
|
void |
removeColumnModelListener(TableColumnModelListener x)
删除表列模型事件的侦听器。
|
void |
setColumnMargin(int newMargin)
将列边距设置为
newMargin 。
|
void |
setColumnSelectionAllowed(boolean flag)
设置是否允许列选择。
|
void |
setSelectionModel(ListSelectionModel newModel)
设置此选择模型
TableColumnModel至
newModel ,并注册了来自新选择模型的通知。
|
void |
valueChanged(ListSelectionEvent e)
A
ListSelectionListener ,当有列选择更改时转发
ListSelectionEvents 。
|
protected Vector<TableColumn> tableColumns
protected ListSelectionModel selectionModel
protected int columnMargin
protected EventListenerList listenerList
protected transient ChangeEvent changeEvent
protected boolean columnSelectionAllowed
protected int totalColumnWidth
public void addColumn(TableColumn aColumn)
aColumn追加到tableColumns数组的末尾。
该方法还将columnAdded事件发布到其监听器。
addColumn在接口
TableColumnModel
aColumn - 要加入的
TableColumn
IllegalArgumentException - 如果
aColumn是
null
removeColumn(javax.swing.table.TableColumn)
public void removeColumn(TableColumn column)
column从tableColumns阵列。
如果column不在表的列列表中,则此方法将column 。
tile来调整头和表视图的大小。
此方法还会向其听众发送一个columnRemoved事件。
removeColumn在界面
TableColumnModel
column - 要删除的
TableColumn
addColumn(javax.swing.table.TableColumn)
public void moveColumn(int columnIndex,
int newIndex)
columnIndex到newIndex 。
columnIndex的旧栏现在将在newIndex找到。
过去是newIndex的列向左或向右移动以腾出空间。
如果columnIndex等于newIndex则不会移动任何列。
此方法还会columnMoved者发送一个columnMoved事件。
moveColumn在接口
TableColumnModel
columnIndex - 要移动的列的索引
newIndex - 移动列的新索引
IllegalArgumentException - 如果
column或
newIndex不在有效范围内
public void setColumnMargin(int newMargin)
newMargin 。
此方法还columnMarginChanged者发送了一个columnMarginChanged事件。
setColumnMargin在界面
TableColumnModel
newMargin - 新的边距宽度,以像素为单位
getColumnMargin() ,
getTotalColumnWidth()
public int getColumnCount()
tableColumns数组中的列数。
getColumnCount在界面
TableColumnModel
tableColumns数组中的列数
getColumns()
public Enumeration<TableColumn> getColumns()
Enumeration中所有列的
Enumeration 。
getColumns在接口
TableColumnModel
Enumeration的列中的模型
public int getColumnIndex(Object identifier)
equals进行比较时,返回标识符等于
identifier的
tableColumns数组中第一列的索引。
getColumnIndex在接口
TableColumnModel
identifier - 标识符对象
identifier的
tableColumns数组中的第一列的索引
IllegalArgumentException - 如果
identifier是
null ,或者如果没有
TableColumn有这个
identifier
getColumn(int)
public TableColumn getColumn(int columnIndex)
TableColumn在列对象
columnIndex 。
getColumn在界面
TableColumnModel
columnIndex - 所需列的索引
TableColumn对象为
columnIndex
public int getColumnMargin()
TableColumn的宽度。
默认的columnMargin是1。
getColumnMargin在界面
TableColumnModel
TableColumn
setColumnMargin(int)
public int getColumnIndexAtX(int x)
x位置的列的索引,如果没有列覆盖此点,则返回-1。
与Swing的可分离模型架构保持一致,TableColumnModel不知道表列如何在屏幕上实际显示。
列的视觉呈现是使用此模型(通常为JTable)的视图/控制器对象的责任。
视图/控制器不需要从左到右依次显示列。
例如,可以从右到左显示列,以容纳区域设置首选项,或者可能在用户的请求下隐藏某些列。
因为模型不知道列如何布置在屏幕上,所以给定的xPosition不应该被认为是2D图形空间中的坐标。
相反,它应该被认为是从模型中第一列开始的宽度。
如果需要2D空间中给定的X坐标的列索引, JTable.columnAtPoint可以使用JTable.columnAtPoint 。
getColumnIndexAtX在接口
TableColumnModel
x - 感兴趣的水平位置
JTable.columnAtPoint(java.awt.Point)
public int getTotalColumnWidth()
getTotalColumnWidth在界面
TableColumnModel
totalColumnWidth属性
public void setSelectionModel(ListSelectionModel newModel)
TableColumnModel至newModel ,并注册了来自新选择模型的通知。
如果newModel是null ,则抛出异常。
setSelectionModel在接口
TableColumnModel
newModel - 新的选择模式
IllegalArgumentException - 如果
newModel是
null
getSelectionModel()
public ListSelectionModel getSelectionModel()
ListSelectionModel用来维护列选择状态。
getSelectionModel在界面
TableColumnModel
null如果不允许行选择。
setSelectionModel(javax.swing.ListSelectionModel)
public void setColumnSelectionAllowed(boolean flag)
setColumnSelectionAllowed在接口
TableColumnModel
flag - 如果列选择将被允许,则为true,否则为false
TableColumnModel.getColumnSelectionAllowed()
public boolean getColumnSelectionAllowed()
getColumnSelectionAllowed在界面
TableColumnModel
columnSelectionAllowed属性
TableColumnModel.setColumnSelectionAllowed(boolean)
public int[] getSelectedColumns()
selectionModel为null ,则返回一个空数组。
getSelectedColumns在接口
TableColumnModel
selectionModel是
null
public int getSelectedColumnCount()
getSelectedColumnCount在界面
TableColumnModel
public void addColumnModelListener(TableColumnModelListener x)
addColumnModelListener在界面
TableColumnModel
x - 一个
TableColumnModelListener对象
public void removeColumnModelListener(TableColumnModelListener x)
removeColumnModelListener在界面
TableColumnModel
x - 一个
TableColumnModelListener对象
public TableColumnModelListener[] getColumnModelListeners()
ColumnModelListener s或一个空数组,如果没有列模型侦听器当前注册
addColumnModelListener(javax.swing.event.TableColumnModelListener) ,
removeColumnModelListener(javax.swing.event.TableColumnModelListener)
protected void fireColumnAdded(TableColumnModelEvent e)
e - 收到的事件
EventListenerList
protected void fireColumnRemoved(TableColumnModelEvent e)
e - 收到的事件
EventListenerList
protected void fireColumnMoved(TableColumnModelEvent e)
e - 收到的事件
EventListenerList
protected void fireColumnSelectionChanged(ListSelectionEvent e)
e - 收到的事件
EventListenerList
protected void fireColumnMarginChanged()
EventListenerList
public <T extends EventListener> T[] getListeners(类<T> listenerType)
FooListener的所有对象的数组。
FooListener使用addFooListener 。
您可以使用类文字指定listenerType参数,例如FooListener.class 。 例如,您可以使用以下代码查询DefaultTableColumnModel m其列模型侦听器:
ColumnModelListener[] cmls = (ColumnModelListener[])(m.getListeners(ColumnModelListener.class));
如果没有这样的侦听器存在,这个方法返回一个空数组。
listenerType - 所请求的听众的类型;
此参数应指定从java.util.EventListener下降的java.util.EventListener
FooListener的所有对象的数组,如果没有添加此类侦听器,则为空数组
ClassCastException - 如果
listenerType未指定实现java.util.EventListener的类或
java.util.EventListener
getColumnModelListeners()
public void propertyChange(PropertyChangeEvent evt)
propertyChange在界面
PropertyChangeListener
evt -
PropertyChangeEvent
public void valueChanged(ListSelectionEvent e)
ListSelectionListener转发
ListSelectionEvents时,有一个列选择变化。
valueChanged在界面
ListSelectionListener
e - 变更事件
protected ListSelectionModel createSelectionModel()
protected void recalcWidthCache()
totalColumnWidth property.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.