JTable的boolean列的全选/反选/全不选
1、JTable的boolean列的全选/反选/全不选
/**
*
* @Title: selectAll
* @Description: TODO 全选
* @param table
* @param checkColumnIndex
* @Author:wushigao
* @CreateDate:2023年4月25日 上午11:32:16
*/
public static void selectAll(JTable table ,int checkColumnIndex) {
stopEdit(table);
int rowCount = table.getRowCount();
if(rowCount > 0) {
for(int rowIndex = 0; rowIndex<rowCount; rowIndex++) {
table.setValueAt(true, rowIndex, checkColumnIndex);
}
}
}
/**
*
* @Title: reverseSelection
* @Description: TODO 反选
* @param table
* @param checkColumnIndex
* @Author:wushigao
* @CreateDate:2023年4月25日 上午11:36:00
*/
public static void reverseSelection(JTable table ,int checkColumnIndex) {
stopEdit(table);
int rowCount = table.getRowCount();
if(rowCount > 0) {
for(int rowIndex = 0; rowIndex<rowCount; rowIndex++) {
boolean select = (boolean) table.getValueAt(rowIndex, checkColumnIndex);
table.setValueAt(!select, rowIndex, checkColumnIndex);
}
}
}
/**
*
* @Title: chooseNothing
* @Description: TODO 全不选
* @param table
* @param checkColumnIndex
* @Author:wushigao
* @CreateDate:2023年4月25日 上午11:36:55
*/
public static void chooseNothing(JTable table ,int checkColumnIndex) {
stopEdit(table);
int rowCount = table.getRowCount();
if(rowCount > 0) {
for(int rowIndex = 0; rowIndex<rowCount; rowIndex++) {
table.setValueAt(false, rowIndex, checkColumnIndex);
}
}
}

浙公网安备 33010602011771号