2014-01-07 36 views
-1

我有一个包含列数的表。我通过createCell方法添加了一列CheckBox组件。该添加的列应该是第一列(索引0的列)。添加一列后,另一列隐藏在我的表

我的问题只是当我运行的代码先前的第一列(学生号码)不显示。 在我看来,添加的列覆盖了下一列。

请问如何解决这个问题?

TableModel model = new DefaultTableModel(new String[] {"Student-Number","Student-name","Degree"} ,ob) { 
public boolean isCellEditable(int row, int col) 
     { 
     return true; 
     } 

     }; 

Table table = new Table(model,true) 

{ 
protected Component createCell(Object value, final int row, 
final int column, boolean editable) { 

if (column == 0) 
{ 

CheckBox cod= new CheckBox ("cod"); 
return cod; 
} 
return super.createCell(value, row, column, editable); 
} 
} ; 
+1

为了更快提供更好的帮助,请发布[SSCCE](http://sscce.org/)。 –

+0

是的同意(不包括99%的用户在这里)我们这里不是代码引擎............... – mKorbel

+0

请赐教我是我的代码长还是不独立? – JavaFan

回答

1

你展示的代码是通常的方法来获得复选框在JTable。对于Boolean.class类型的数据,您应该使用默认的renderer and editor。该教程的TableSelectionDemo是一个很好的示例。