| |
在一个表格监听列相关的变化事件 |
|
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;
public class Main {
public static void main(String[] argv) throws Exception {
JTable table = new JTable();
table.getColumnModel().addColumnModelListener(new MyTableColumnModelListener(table));
}
}
class MyTableColumnModelListener implements TableColumnModelListener {
JTable table;
public MyTableColumnModelListener(JTable table) {
this.table = table;
}
public void columnAdded(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnRemoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnMoved(TableColumnModelEvent e) {
int fromIndex = e.getFromIndex();
int toIndex = e.getToIndex();
System.out.println(fromIndex);
System.out.println(toIndex);
}
public void columnMarginChanged(ChangeEvent e) {
System.out.println(e);
}
public void columnSelectionChanged(ListSelectionEvent e) {
System.out.println(e);
}
}
|
|
|
Related examples in the same category |
1. | 创建一个表格 | | | 2. | Creates tables that allow rows and columns to be added or deleted | | | 3. | 从列表数据和列名建立一个表 | | | 4. | Getting the Number of Rows and Columns in a JTable Component | | | 5. | 添加数据到表格组件 | | | 6. | 通过DefaultTableModel添加列到表格 | | | 7. | 通过DefaultTableModel插入一行到表格 | | | 8. | Insert a row to a table through DefaultTableModel at specified row | | | 9. | 滚动表 | | | 10. | 简单示范表格 | | | 11. | 创建一个表从两个二维数组 | | | 12. | 创建表与Unicode数据 | | | 13. | 使用表,以显示输入的数据(整数,布尔,彩色) | | | 14. | 调整表的大小 | | | 15. | 费用表 | | | 16. | StockTable 6:事件和动态显示 | | | 17. | 表格选择事件 | | | 18. | 表行和列的选择 | | | 19. | 表选择模式 | | | 20. | Use code to change Table Selection | | | 21. | 结果显示在表(表格) | | | 22. | 表格与JDBC结果 | | | 23. | 结果表:继承AbstractTable和JDBC结果集ResultSet | | | 24. | 列表界面性能,表格和排序 | | | 25. | 属性表:使用表格来显示和编辑属性 | | | 26. | 表与工具提示,单元格和列标题 | | | 27. | StockTable 4 :表排序 | | | 28. | Table Sort Test | | | 29. | 表格排序:点击表头进行表排序 | | | 30. | 创建表格的图像 | | | 31. | JTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); | | | 32. | JTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | | | 33. | JTable.setColumnSelectionAllowed(boolean b); | | | 34. | JTable.setRowSelectionAllowed(boolean b); | | | 35. | JTable.setCellSelectionEnabled(boolean b); | | | 36. | 处理选择和模型的变化事件 | | | 37. | ListSelectionModel rowSelMod = JTable.getSelectionModel(); | | | 38. | ListSelectionModel colSelMod = JTable.getColumnModel().getSelectionModel(); | | | 39. | JTree.getModel().addTreeModelListener(new TreeModelListener()) | | | 40. | Move the last visible column so it becomes the first visible column | | | 41. | the last column is moved to the first position | | | 42. | 在一个表格允许用户调整列 | | | 43. | 检索表中可见单元格的值 | | | 44. | 从模型中检索表中的数据 | | | 45. | Change a cell in the 2nd visible column | | | 46. | Change a cell in the 3rd column in the model | | | 47. | 在非可卷动的表格显示表头 | | | 48. | 在一个表格改变列名称 | | | 49. | 在表头显示图标 | | | 50. | Implementing Variable-Height Column Headers in a JTable Component | | | 51. | Removing the Column Headers from a Scrollable in a JTable Component | | | 52. | Creating a Custom Column Header Renderer in a JTable Component | | | 53. | Setting Column Header Tool Tips in a JTable Components | | | 54. | 对表格单元格组件设置工具提示 | | | 55. | 在表格使行默认选择 | | | 56. | 在表格设置有效列 | | | 57. | 选择表格单元格 | | | 58. | 得到默认的选择模式: MULTIPLE_INTERVAL_SELECTION | | | 59. | 只允许单一选择 | | | 60. | Allow selection to span one contiguous set of rows, visible columns, or block of cells | | | 61. | Allow multiple selections of rows, visible columns, or cell blocks (default) | | | 62. | 选择一个列 | | | 63. | 选择一个系列 | | | 64. | 取消一系列栏的选择 | | | 65. | 选中某行-列0 | | | 66. | 选择一个额外的一系列行 | | | 67. | 取消一系列行的选择 | | | 68. | 选择一个单元格:单元格( 2,1 ) | | | 69. | 将选定内容扩展到包括所有单元格( 5,3 ) | | | 70. | Deselect a cell: cell (3,2), All cells in the row and column containing (3,2) are deselected. | | | 71. | Toggles the selection state, if it were called again, it exactly reverses the first call. | | | 72. | 选择所有单元格 | | | 73. | 取消所有单元格 | | | 74. | Column selection is enabled, get the indices of the selected columns | | | 75. | Row selection is enabled, Get the indices of the selected rows | | | 76. | 活动被选定行的索引 | | | 77. | 获得最大和最小范围内选定的单元格 | | | 78. | Check each cell in the min and max ranges of selected cells | | | 79. | 在一个表格禁用选则 | | | 80. | 获得选中的表单元格 | | | 81. | 建立一个可滚动表格 | | | 82. | Disable auto resizing to make the table horizontal scrollable | | | 83. | 确定是否一个单元格可见 | | | 84. | 使表格中的单元格可见 | | | 85. | 滚动单元格 | | | 86. | 显示横向和纵向网格线(默认) | | | 87. | 不显示任何网格线 | | | 88. | 只显示垂直网格线 | | | 89. | 只显示水平网格线 | | | 90. | 设置网格颜色 | | | 91. | 获取表格组件单元格之间间隙的大小 | | | 92. | 在单元格的左右添加空格 | | | 93. | 增加行高 | | | 94. | Programmatically Starting Cell Editing in a JTable Component | | | 95. | Save the current value in the cell being edited and stops the editing process | | | 96. | Discard any changes made by the user and stops the editing process | | | 97. | 禁用用户编辑表格 | | | 98. | 禁用用户编辑表格与DefaultTableModel | | | 99. | 基于列在一个表格排序列 | | | 100. | 表格排序列 | | | 101. | 表格组件选择事件监听 | | | 102. | Listening for Changes to the Rows and Columns of a JTable Component | | | 103. | Listening for Clicks on a Column Header in a JTable Component | | | 104. | 排序和筛选表 | | | 105. | 使用regexFilter过滤表 | | | 106. | 设置表格行高度 | | |
|