samedi 21 février 2015

How to make JCheckBox from text file data

I have an JTable which is displaying data from a file. I want to have in this JTable a column of checkboxes. I know I have to override getColumnClass method to return Boolean.class. I'm doing this this way:



private DefaultTableModel tableModel = tableModel = new DefaultTableModel(0, col.length){
public Class<?> getColumnClass(int colIndex) {
if (colIndex == 6)
return java.lang.Boolean.class;
else
return java.lang.Object.class;
}
};


As I said data for JTable is stored in txt file. I know how to read it to display all things in table, but I don't know how I can make set checkboxes to display values (true, false). My file looks like this:



aaaaaaaaaa|cw27729|604208652|16/02/2015|description|cost|Here i want data for checkboxes|
sdfsdf|sdfdsf|sdfsf|16/02/2015|description|cost|Here i want data for checkboxes|


So if there is no text in last column in file table is displaying empty checkboxes, which is fine. But what should my file look like if i want checkbox to be checked? I tried Boolean.TRUE, true, or differnt wierd things and I always get a lot of errors.


I think it's beacuse when I'm reading a file all data are in String format and there should be Boolean.Class in column which is supposed to display checkboxes.


Can anyone kind help me? Sorry if my English is bad, it is not my native language.





Aucun commentaire:

Enregistrer un commentaire