munky.net

design and open source

CellRenderer setValue behavior

| 0 comments

In the CellRenderer API, the setValue method takes a parameter called “selected”, which is documented to be a boolean indicating whether the cell being rendered is currently selected. In fact, the selected parameter is a String whose possible values are “normal”, “highlighted”, and “selected”. Thus if you treat the parameter as a boolean you’ll always end up with a value of true.

Unfortunately, the “highlighted” value appears to override the “selected” value, so if a row is selected and the cursor is on top of it, the value of the selected param will be “highlighted” and not “selected”. This can cause problems if you’re trying to make the renderer behave differently based on whether or not the row is in a selected state, since if you use the selected param the row will only appear as selected when the mouse is not hovering over it. This can be worked around by using the expression

var reallySelected:Boolean = selected ne "normal" && listOwner.selectedNode == item;

instead to test whether the node for the current row is in a selected state. I’m not sure why the first term of the expression (the “normal” check) is necessary, but I had to include that in order to avoid false positives — I think it has to do with the details of the order in which the various selected flags get updated by the model and component.

Leave a Reply

Required fields are marked *.