I'm using Glazed lists, in a jTable
where I have a column which is boolean.
By default the jTable
renders a checkbox where the column is type Boolean.Class
.
Using Glazed lists i cannot get the checkbox which is needed. I rendered checkboxs extending the DefaultTableCellRenderer
but i'm not satisfied with it because the checkboxs are not "clickable".
In the GL faq http://www.glazedlists.com/documentation/faq i found:
*Q: How do I specify that my boolean table cells be rendered with a checkbox? For some reason, Glazed Lists has no getColumnClass() method.
A: If you need to specify the column class, you need to implement the AdvancedTableFormat interface instead of the regular TableFormat class. If you are using the GlazedLists.tableFormat() factory method, you must specify the base Object's class for a proper implementation of the AdvancedTableFormat.getColumnClass() method.*
Does some of you have experience with this I did not find any links with an example. The essential link in the faq is broken.
I tried with this:
public class CheckBoxTableModel implements AdvancedTableFormat {
public Class getColumnClass(int column) {
if(column==4)
return Boolean.class;
else
return Object.class;
}
}
Please help!
EDIT: I tried with this, the form with the jtable does not show
private class TicketTableFormat implements AdvancedTableFormat<Ticket> {
private final String[] cols = new String[]{"Id", "From", "Subject", "Date", "Incomplete"};
public int getColumnCount() {
return cols.length;
}
public String getColumnName(int colId) {
return cols[colId];
}
public Class getColumnClass(int col) {
if (col == 4) {
return Boolean.class;
} else {
return Object.class;
}
}
public Object getColumnValue(Ticket ticket, int colId) {
switch (colId) {
case 0:
return ticket.getId();
case 1:
return ticket.getFrom();
case 2:
return ticket.getSubject();
case 3:
return ticket.getDate();
case 4:
return ticket.getIncomplete();
}
return null;
}
public boolean isEditable(Ticket e, int col) {
if (col < 4) {
return false;
} else {
return true;
}
}
public Ticket setColumnValue(Ticket e, Object o, int i) {
e.setB((Boolean) editedValue);
return e;
}
public Comparator getColumnComparator(int i) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
i call it with this:
TicketTableFormat tbFormat = new TicketTableFormat();
TicketsModel = new EventTableModel(textFilteredTickets, tbFormat);
ticketTable.setModel(TicketsModel);
Did you implement isEditable(...) & setColumnValue(...) in your implementation of AdvancedTableFormat?
Implementing the following methods works for me.
Edit: an example (quick and dirty)