Hi Paul,
here is a simple example that should cover both of your recent questions.
It sets a checkbox as a renderer/editor and in keeps the selection
background.
You must set the correct selection background in you renderer code.
To do this you use the "isSelected" argument of the renderer method. It
indicates
whether the currently rendered cell is selected or not.
Hope this helps.
Greetings,
Daniel
------------------
public class Hey extends AbstractApplication {
public void start() {
final ULCFrame frame = new ULCFrame();
frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
final ULCBoxPane pane = new ULCBoxPane();
frame.add(pane);
final ULCCheckBox box = new ULCCheckBox();
final ULCTable table = new ULCTable(new Object[][] { { new
Integer(1), Boolean.TRUE },
{ new Integer(2), Boolean.FALSE } }, new String[] { "A",
"B" });
table.getColumnModel().getColumn(1).setCellRenderer(new
ITableCellRenderer() {
public com.ulcjava.base.application.IRendererComponent
getTableCellRendererComponent(ULCTable table,
Object value, boolean isSelected, boolean hasFocus, int
row) {
box.setSelected(((Boolean)value).booleanValue());
if (isSelected) {
box.setBackground(table.getSelectionBackground());
} else {
box.setBackground(table.getBackground());
}
return box;
}
});
table.getColumnModel().getColumn(1).setCellEditor(new
ITableCellEditor() {
public IEditorComponent getTableCellEditorComponent(ULCTable
table, Object value, int row) {
box.setSelected(((Boolean)value).booleanValue());
box.setBackground(table.getSelectionBackground());
return box;
}
});
pane.add(new ULCScrollPane(table));
final ULCButton button = new ULCButton("Show Data");
pane.add(button);
button.addActionListener(new IActionListener() {
public void
actionPerformed(com.ulcjava.base.application.event.ActionEvent event) {
int row = table.getModel().getRowCount();
for (int i = 0; i < row; i++) {
System.out.println("Row " + i + " column 1: " +
table.getModel().getValueAt(i, 1));
}
};
});
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
DevelopmentRunner.setApplicationClass(Hey.class);
DevelopmentRunner.run();
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Harrison Paul
Sent: Freitag, 14. Juli 2006 12:37
To: [email protected]
Subject: [ULC-developer] ULCTable - Cell renderers
Hello
I am using the ULCTables quite extensively within our application. I need to
format the cells according to database types (chars, numbers, dates,
checkboxes etc). I do this by setting the cell renderes and it works well.
The only problem is, as soon as I set the cell renderers I loose the row
selection! The user can still select rows but there is no record indicator
(coloured row) when selected. This is also the case for column selection. Do
you have any ideas what I should do to get the selection colour back?
Paul Harrison
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer