-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi there,
I want to set a Model to a Combobox and then set the selected index. But after invoking setModel method the model is
still not set.
...
box.getItemCount(); //returns maybe 0
box.setModel( new ListModelList(anyList));
box.getItemCount(); //still returns 0
...
I can select items from the right model afterwards in the presentation though. So it gets set, but far too late.
What to do?
Thanks in advance!
According the implementation.
public List getItems() {
return getChildren();
}
/** Returns the number of items.
*/
public int getItemCount() {
return getItems().size();
}
It's really late.
But you can use sizeof ListModelList(anyList) as a workaround.
Hi,
thanks for your reply! But this is not satisfying. I need to select the index of the combobox.
The detailes problem:
I have 2 Comboboxes with the same Model (e.g. dates, range of 5 days), a "from" and a "to" box.
When selecting a date of the from box the selection range of the to box shall be restricted to not be able selecting days before the from box.
And yes, i need it this way, no dateboxes or other components as workaround.
Isn't there a fix for it? Why is the update of the combobox late?
Thanks!
I found a solution myself.
Never use comboboxes! Use listboxes (with mold="select it has the same design as a combobox) instead.
After setting the model invoke renderAll method and everything is working fine.
Another question is: Why are there comboboxes in the framework at all?
When using a model, I set the combo to listen to the onInitRenderLater event to set the index. Here is an example of a combobox in Java:
public class CatCombo extends Combobox { private ArrayList subcats; private int index=0; public CatCombo(ArrayList subcats) { this.subcats = subcats; ListModelList model = new ListModelList(subcats); this.setModel(model); this.addEventListener("onInitRenderLater", new EventListener() { public void onEvent(Event e) throws Exception { CatCombo.this.setSelectedIndex(index); } }); } public void setSelected(String subcat){ index = subcats.indexOf(subcat); } }
Damn!
I have troubled with the same problem about a day!
Thank you, sensdb
PeterKuo, I think it will better to mark Combobox @deprecated .
Asked: 2011-05-05 08:20:51 +0800
Seen: 1,476 times
Last updated: Aug 17 '12