简单问题100分:如何使JTable的单元格(或行)可以选择而不能编辑??

猛将 2001-12-10 11:23:03
如何使JTable的单元格(或行)可以选择而不能编辑??给个例子,谢谢!
...全文
169 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
vdragon 2001-12-10
  • 打赏
  • 举报
回复
isCellSelected
public boolean isCellSelected(int row,
int column)Returns true if the cell at the specified position is selected.
Parameters:
row - the row being queried
column - the column being queried
Returns:
true if the cell at index (row, column) is selected, where the first row and first column are at index 0


isRowSelected
public boolean isRowSelected(int row)Returns true if the row at the specified index is selected.
Returns:
true if the row at index row is selected, where 0 is the first row
vdragon 2001-12-10
  • 打赏
  • 举报
回复
isCellEditable
public boolean isCellEditable(int row,
int column)Returns true if the cell at row and column is editable. Otherwise, invoking setValueAt on the cell will have no effect.
Note: The column is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, the column at a given index in the view will change. Meanwhile the user's actions never affect the model's column ordering.

Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
true if the cell is editable
rinehart 2001-12-10
  • 打赏
  • 举报
回复
自己定义一个类继承DefaultTableModel
然后重载以下方法:
public boolean isCellEditable(int pRow, int pCol) {
return false;
}
就可以了!
只能选择,不能编辑!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧