Combobox setModel method does not update immediately

asked 2011-05-05 08:20:51 +0800

sensdb gravatar image sensdb
21 2

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!

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-05-13 02:20:27 +0800

PeterKuo gravatar image PeterKuo
481 2

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.

link publish delete flag offensive edit

answered 2011-05-19 03:03:35 +0800

sensdb gravatar image sensdb
21 2


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?


link publish delete flag offensive edit

answered 2011-08-04 06:34:43 +0800

sensdb gravatar image sensdb
21 2

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?

link publish delete flag offensive edit

answered 2011-08-05 01:36:54 +0800

RichardL gravatar image RichardL
768 4

updated 2011-08-05 01:37:58 +0800

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.addEventListener("onInitRenderLater", new EventListener() {

            public void onEvent(Event e) throws Exception {
    public void setSelected(String subcat){
        index = subcats.indexOf(subcat);

Hope it helps,

link publish delete flag offensive edit

answered 2012-08-17 13:18:59 +0800

kcvilyov gravatar image kcvilyov

updated 2012-08-17 13:22:08 +0800

I have troubled with the same problem about a day!
Thank you, sensdb
PeterKuo, I think it will better to mark Combobox @deprecated .

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2011-05-05 08:20:51 +0800

Seen: 1,474 times

Last updated: Aug 17 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More