-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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:
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
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());
}
Thanks Neillee for your answer and for your workaround!!
Claudio
Asked: 2013-11-08 10:28:51 +0800
Seen: 48 times
Last updated: Nov 11 '13