How to use ListBox.addClickCommands()?

I did set ListBox.addClickCommands() properly (AFAIK)
but while debugging, when clicking on a ListBox item/entry, it recognizes ListAction.Down, and wont recognize ListAction.Click,
so I used ListBox.addCommands(ListAction.Down,... instead

Maybe the elements in the list box are consuming the up? Still weird.

Are you using this for effects or something? There are generally better ways to tell when a selection has changed.

I coded so I click on a listbox item and its contents are copied to one input textfield.
I didnt code the Up for anything.
Mmm… I should check on the update if the selected has changed? and/or use some versioned reference?

Yep, that’s the better way as then you will see the selection change even if set programatically somewhere else.

Just a grab a reference to the current selection and when it updates, update your text.

1 Like

works, nice thx!

lstbx.getSelectionModel().createReference();

if(!refSelectionModel.needsUpdate())return;
refSelectionModel.update();

[details=btw, just a thouight]that two steps update could be 1:

if(!refSelectionModel.isNeedsAndUpdate())return;

but, at least, that method name I created may be quite confusing, I know.[/details]

if( refSelectionModel.update() ) {
// set your text
}

I don’t know why you do the two step way.

needsUpdate() is there for if you want to check if it needs an update without actually moving the version forward. It’s a rare use-case, though.

2 Likes