Jtable with first of JCheckBoxes
I need to have checkboxes on the first row of the Table and when I tick them i need to do something else (didn't got to that part yet). Anyway, so I have a vector of Booleans but I can only get to see true or false instead of the checkboxes.
publicclass DataFileTabelModelextends AbstractTableModel{
protected Vector<String> data;
protected Vector<Boolean> chkb;
protected Vector<String> columnNames ;
protected String datafile;
publicstaticint numlines=0;
publicstaticint numcol=0;
public DataFileTabelModel(String fname)throws IOException{
initVectors(fname);
}
publicvoid initVectors(String fname)throws IOException{
String aLine ;
chkb =new Vector<Boolean>();
data =new Vector<String>();
BufferedReader in =new BufferedReader(new FileReader(fname));
String str="";
int numlines=0;
int numcol=0;
//se numara liniile si coloane
while ((str = in.readLine()) !=null)
{
numlines++;
StringTokenizer st=new StringTokenizer(str," ");
numcol=st.countTokens();
}
float a[][]=newfloat[numlines][numcol];
columnNames =new Vector<String>();
Vector<String> subt=new Vector<String>();
String linie="";
BufferedReader br;
try{
br =new BufferedReader(new FileReader(fname));
while((linie=br.readLine())!=null)
subt.add(linie);
for(int i=0;i<subt.size();i++)
{
StringTokenizer st=new StringTokenizer(subt.get(i)," ");
for(int j=0;j<numcol;j++)
a[i][j]=Float.parseFloat(st.nextToken());
}
for(int i=0;i<numcol;i++){
columnNames.addElement("Col"+i);
chkb.addElement(Boolean.FALSE);
}
for(int i = 0;i >< numlines;i++ )
for(int j=0;j < numcol;j++ )
data.addElement(String.valueOf(a[i][j]));
}catch (Exception ex){
ex.printStackTrace();
}
}
publicint getRowCount(){
return data.size() / getColumnCount();
}
publicint getColumnCount(){
return columnNames.size();
}
public String getColumnName(int columnIndex){
String colName ="";
if (columnIndex <= getColumnCount())
colName = columnNames.elementAt(columnIndex);
return colName;
}
public Class getColumnClass(int columnIndex){
return getValueAt(0, columnIndex).getClass();
}
publicboolean isCellEditable(int rowIndex,int columnIndex){
returntrue;
}
publicvoid removeRow(int rowIndex)
{
for(int i = 0;i < getColumnCount();i++)
data.removeElementAt((rowIndex * getColumnCount()));
}
public Object fasule(int rowIndex,int columnIndex){
return data.elementAt
( (rowIndex * getColumnCount()) + columnIndex);
}
public Object getValueAt(int rowIndex,int columnIndex){
if (rowIndex==0)return chkb.elementAt( (rowIndex * getColumnCount()) + columnIndex);
elsereturn data.elementAt
( (rowIndex * getColumnCount()) + columnIndex);
}
publicvoid setValueAt(Object aValue,int rowIndex,int columnIndex){
data.setElementAt((String)aValue,(rowIndex * getColumnCount()) + columnIndex);
}
}
Where's the problem?

