我在Jtalbe中有一列需要显示checkbox,现在的问题是checkbox可以显示,但是不能被勾选,isEditable()已经返回true了啊,该列的cellRenderer如下:
public class RepeatAttributeCellRenderer implements TableCellRenderer, Serializable {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
System.out.println(value.toString()+" row="+row+" cloumn="+column);
Component component = null;
SelectedAttributesTableModel model = (SelectedAttributesTableModel)table.getModel();
JCheckBox checkBox = SubtotalCellRenderer.buildCheckBox(table, isSelected, hasFocus);
boolean isSubTotalSelected = ((Boolean)model.getValueAt(row, column-1)).booleanValue();
checkBox.setEnabled(isSubTotalSelected);
checkBox.setSelected(((Boolean)value).booleanValue());
component = checkBox;
return component;
}
}小弟,对java GUI开发不是很熟悉,请各位高手帮忙看下,这个问题已经困扰小弟一天了,急啊!!!
public class RepeatAttributeCellRenderer implements TableCellRenderer, Serializable {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
System.out.println(value.toString()+" row="+row+" cloumn="+column);
Component component = null;
SelectedAttributesTableModel model = (SelectedAttributesTableModel)table.getModel();
JCheckBox checkBox = SubtotalCellRenderer.buildCheckBox(table, isSelected, hasFocus);
boolean isSubTotalSelected = ((Boolean)model.getValueAt(row, column-1)).booleanValue();
checkBox.setEnabled(isSubTotalSelected);
checkBox.setSelected(((Boolean)value).booleanValue());
component = checkBox;
return component;
}
}小弟,对java GUI开发不是很熟悉,请各位高手帮忙看下,这个问题已经困扰小弟一天了,急啊!!!
解决方案 »
- 求教一个窗口最大化有点灵异的问题
- JDK里面的lib、src?
- 关于Java se中Iterator的疑问 请高手具体点解答
- qq有消息 时 Scroll Lock 灯闪烁
- 弱弱的一问
- 郁闷了!Jnative调用dll错误,Not found the kernel library...
- 一段写好的JAVA程序 怎么让他可以定时执行?
- Java开发精华文摘
- Java搜索database时,出现 非法的游标状态 报错
- 这个问题如何解?
- 请问如何在不使用java.util包的情况下使用链表实现任意长整数的加减运算?
- Socket FTP 流的同步问题,本地流用FTPClient向服务端写文件后,服务端的文件不完整
checkBox.setEnabled(isSubTotalSelected);
的isSubTotalSelected 值是什么,改一下试
class MyTableModel extends DefaultTableModel{
public MyTableModel(Vector data,Vector columns){
super(data,columns);
}
public boolean isCellEditable(int row,int column){
return true; }
public Class<?> getColumnClass(int columnIndex) {
if(columnIndex==0){ //設置第幾列是checkbox
return Boolean.class;
}
return Object.class;
}
}