0

visibleItemCount for Listbox does not reset on getItems().clear()

asked 2015-06-13 22:05:14 +0800

HoofyDough gravatar image HoofyDough
1

As title states, I have a listbox of items (my example, _items = 223) and I need to clear all items and re-render the listbox with a new set of items.

Using listbox.getItems().clear() does remove all items just fine and when I add a new set of items (let's say _items = 30 now), there will only be 30 items visible in the listbox.

Behind the scenes though, if I call listbox.getVisibleItemCount(), I get the value 253 (223 previous items + 30 new items). Basically if I clear all items and re-render enough times in the same session, the visibleItemCount can grow rather large.

I am using a ListitemRenderer to add the items to the listbox which may have an effect on this behavior.

It's really a minor issue because I don't like that value growing uncontrollably. Anyway to reset that value manually? Or am I stuck with that value continually growing each time I re-render the listbox with new items?

Below is an example of my function:

private void setListbox(List list)
{
   try {
        listbox.getItems().clear();
        System.out.println(listbox.getVisibleItemCount() + " " + listbox.getItemCount());
        ListModel listModel = new ListModelGen(list);
        listbox.setModel(listModel);
        ListitemRenderer listitemRenderer = new ListItemRendererGen();
        listbox.setItemRenderer(listitemRenderer);
   }
   catch (Exception e)
   {
       e.printStackTrace();
   }
}

Let's say I call setListbox 4 times with a list size of 223, my console will print out the following:

0 0
223 0
446 0
669 0

VisibleItemCount() on the left and getItemCount() on the right.

delete flag offensive retag edit
Be the first one to answer this question!
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

Follow
1 follower

RSS

Stats

Asked: 2015-06-13 22:05:14 +0800

Seen: 13 times

Last updated: Jun 13 '15

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