Dynamically Change Item Icon

When a user clicks on a Table row, I want to change the row’s icon as visual feedback. Here’s the code I have, but it isn’t working. Icon doesn’t change.

    table.addListener(new Table.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
        	String rowID = (String)event.getProperty().getValue();
        	
        	if (rowID != null)
        	{
        		table.setItemIcon(rowID, new ThemeResource("icons\clicked.gif"));
        	}
        }
    });

Thanks.

Bill

Have you put your table into immediate mode (
table.setImmediate(true)
)? This is needed in order for the value change events to be passed back to the server right after the value (selected row) is changed in the client.

On first thought, I think you should set table.immediate(true) and also refresh your container. (Destroy and rebuild ).

Yes, I 've issued setImmediate(true), and the event routine is being executed. Can you tell me what you mean by “Destroy and Rebuid”? Do you mean to recreate the entire table? Is that really necessary just to change one cell value?

Thanks.

BIll

Update: If, for example, I click on the table header to re-sort after the row has been clicked, then the new icon shows up. So the problem must have something to do with the screen not being refreshed. I’ve added a
table.requestRepaint();
in the handler, but screen still doesn’t update.

Bill

Exactly, that is what I meant.

Okay, I added a call to sort() in the handler, and that updates the screen, leaving the sort order the same.

As another alternative I subclassed the Table component and added the following method

public void refreshCells () {
resetPageBuffer();
super.refreshRenderedCells();
}

which I call after I update the property.