0

Wrong scrollbar position when clear listbox items

asked 2013-11-08 10:28:51 +0800

claudioveryant gravatar image claudioveryant
9 1

updated 2013-11-11 03:56:45 +0800

neillee gravatar image neillee flag of Taiwan
1692 1 5
https://plus.google.com/u...

Hi all,

I using a listbox with a redefined model from AbstractListModel. If I select an item in a listbox after a scroll and after I reset (clear) all the item of a listbox control, the scrollbar is always visible and always with the last value. Where is my mistake?

<zk>
    <vbox>
        <label value="1) click on 'Load' to load the data;" />
        <label value="2) click to select an item that is not visible (i.e. '18') of the list;" />
        <label value="3) click on 'Reset';" />
        <label value="Now you can to see that the scroll bar is alway visibled and in the old position;" />
        <label value="Note: if at the point (2) you select an item 'visible' (i.e. '5') then the Reset work well and the scrollbar disapper." />
        <label value="Where is my mistake?" />
        <button label="Load" onClick="loadmylist();" />
        <button label="Reset" onClick="resetmylist();" />
        <listbox id="mylist" width="200px" height="200px" >
            <listhead>
                <listheader label="A" />
            </listhead>
        </listbox>
    </vbox>
    <zscript>
    <![CDATA[
      import org.zkoss.zul.event.ListDataEvent;

      private class MyListModel extends AbstractListModel {
         private Vector delegate;
         public MyListModel() {
            delegate = new Vector();
         }
         public Object getElementAt(int index) {
            if(index >= 0 && index < delegate.size())
               return (String) delegate.elementAt(index);
            return "";
         }
         public int getSize() {
            return delegate.size();
         }
         public void removeAllElements() {
            int size = delegate.size();
            if (size > 0) {
               delegate.removeAllElements();
               fireEvent(ListDataEvent.INTERVAL_REMOVED, 0, size - 1);
            }
         }
         public void addElement(String item) {
            int size = delegate.size();
            delegate.addElement(item);
            fireEvent(ListDataEvent.INTERVAL_ADDED, size, size);
         }
      }
      public void resetmylist() {
          mylist.clearSelection();
          mylist.getModel().clearSelection();
          mylist.getModel().removeAllElements();
      }
      public void loadmylist() {
         for(int j = 1; j < 21; ++j)
            mylist.getModel().addElement(new Integer(j).toString());
      }
      MyListModel strset2 = new MyListModel(); 
      mylist.setModel(strset2); 
      ]]>;
    </zscript>
</zk>


I work with:

  1. Apache-Tomcat 6.0.37;
  2. ZK 6.5.2 (same with 6.5.4);
  3. Firefox 24.0
  4. Chrome 30.0.1599.101 m
  5. Safari 5.1.7
  6. I.E. 8
  7. Using Opera 12.14 work well!!!

Using firebug I can to see that there is a <a> tag associates to the listbox that (I think...) maintains the current focus references:

<a id="x7KQ9-a" 
    class="z-focus-a" 
    href="javascript:;" 
    onclick="return false;" 
    style="top:562px;left:0px">
</a>

and, always using firebug, if I decrease the top value (i.e. 56px) the scroll bar disappear.

Thank in advance for all answer and happy work for all

Claudio

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-11-11 04:47:12 +0800

neillee gravatar image neillee flag of Taiwan
1692 1 5
https://plus.google.com/u...

The issue has been identified as a ZK bug, and should be fixed in the next freshly. Please follow this bug tracker http://tracker.zkoss.org/browse/ZK-1834 to get the latest update.

Meanwhile, you can reset the model of the listbox to null as a workaround such as the following.

public void resetmylist() {
    mylist.setModel((ListModel)null);
    strset2.clearSelection();
    strset2.removeAllElements();
}

public void loadmylist() {
    mylist.setModel(strset2);
    for(int j = 1; j < 21; ++j)
        mylist.getModel().addElement(new Integer(j).toString());
}
link publish delete flag offensive edit
0

answered 2013-11-11 09:14:57 +0800

claudioveryant gravatar image claudioveryant
9 1

Thanks Neillee for your answer and for your workaround!!

Claudio

link publish delete flag offensive edit
Your answer
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: 2013-11-08 10:28:51 +0800

Seen: 48 times

Last updated: Nov 11 '13

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