📄 tableutils.java
字号:
package com.cownew.ctk.ui.swing;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
public class TableUtils
{
public static void hideColumn(JTable table, int index)
{
//得到列模型
TableColumnModel columnModel = table.getTableHeader().getColumnModel();
//从列模型中得到列顺序为index的列
TableColumn column = columnModel.getColumn(index);
column.setResizable(false);
column.setMinWidth(0);
column.setMaxWidth(0);
}
/**
* 得到表格选定行的制定列的值
* @param table 表格
* @param colId 列id
* @return
*/
public static Object getSelectedColValue(JTable table,String colId)
{
int rowIndex = table.getSelectedRow();
int columnIndex = table.getColumn(colId).getModelIndex();
return table.getModel().getValueAt(rowIndex, columnIndex );
}
/**
* 设定model的第rowindex行的colId列的值
* @param table
* @param rowIndex
* @param colId
* @return
*/
public static Object getValueAt(JTable table, int rowIndex,
String colId)
{
int colIndex = table.getColumn(colId).getModelIndex();
return table.getModel().getValueAt(rowIndex, colIndex);
}
/**
* 得到model的第rowindex行的colId列的值
* @param table
* @param value
* @param rowIndex
* @param colId
*/
public static void setValueAt(JTable table, Object value,
int rowIndex, String colId)
{
int colIndex = table.getColumn(colId).getModelIndex();
table.getModel().setValueAt(value, rowIndex, colIndex);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -