-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi,
when opening a combobox the position of my window is modified. i.e there is
some sort of (horrible) scroll down effect.
FYI combobox is filled dynamically on onOpen event.
How can i keep initial position of the window when opening combobox?
here is part of the code called when opening conmbobox:
deviceCombo.addForward("onOpen", this, "onRefreshDevice", deviceCombo);
public void onRefreshDevice(Event event) {
Combobox devicesCombo = (Combobox) event.getData();
devicesCombo.getChildren().clear();
Device selected = phone.getDevice();
Comboitem item = null;
boolean chooseNextAsDefault = (selected == null);
for (Device device : this.profile.getDevices()) {
item = new Comboitem();
item.setValue(device);
item.setLabel(device.getVisibleName());
devicesCombo.appendChild(item);
if (selected != null && device.getId() == selected.getId()) {
devicesCombo.setSelectedItem(item);
} else if (chooseNextAsDefault) {
devicesCombo.setSelectedItem(item);
this.phone.setDevice(device);
chooseNextAsDefault = false;
}
}
}
I can't reproduce your situation by your sample code.
Maybe you can provide more code that can let others easily reproduce your situation.
Do you enclose the combobox with a window component?
I tried in zk live demo, browse by firefox 3, the popup of combobox won't affect window position.
http://www.zkoss.org/zkdemo/userguide/#f5
But I do notice something strange in your code:
deviceCombo.addForward("onOpen", this, "onRefreshDevice", deviceCombo);
Is deviceCombo a component? or an event?
http://www.zkoss.org/javadoc/3.6/zk/org/zkoss/zk/ui/Component.html
here is a zul and its associated java code...
-----------
<?page title="voip profile configuration" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="win" border="normal" use="com.ubiqube.ses.zk.window.voip.BugCBWindow" xmlns:a="http://www.zkoss.org/2005/zk/annotation"
contentStyle="overflow:auto">
<vbox>
<hbox>
<label>testbug</label>
<combobox id="cb_bug">
</combobox>
</hbox>
</vbox>
<zscript>
win.init();
</zscript>
</window>
</zk>
-----------
import org.apache.log4j.Logger;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Window;
public class BugCBWindow extends Window {
private static final long serialVersionUID = 1L;
final static Logger logger = Logger.getLogger(BugCBWindow.class.getName());
public BugCBWindow() {
}
public void init() throws Exception {
try {
updateCBBug();
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
public void updateCBBug() throws Exception {
Combobox bugCB = (Combobox) getFellow("cb_bug");
chooseDefaultSelectedItem(bugCB);
bugCB.addForward("onOpen", this, "onOpenCB", bugCB);
}
public void onOpenCB(Event event) {
Combobox combobox = (Combobox) event.getData();
Comboitem item = combobox.getSelectedItem();
String selectedValue = (item == null) ? null : (String) combobox.getSelectedItem().getValue();
combobox.getChildren().clear();
for (int i = 0; i < 15; i++) {
String value = "" + i;
item = new Comboitem();
item.setValue(value);
item.setLabel(value);
combobox.appendChild(item);
if (selectedValue != null && value.equals(selectedValue)) {
combobox.setSelectedItem(item);
}
}
}
public static Combobox chooseDefaultSelectedItem(Combobox combobox) {
combobox.getChildren().clear();
String selectedValue = "" + 1;
Comboitem item = new Comboitem();
item.setValue(selectedValue);
item.setLabel(selectedValue);
combobox.appendChild(item);
combobox.setSelectedItem(item);
return combobox;
}
}
By deploy your sample code, and browser by ff3, I still not seen position of my window is modified
But I see the combobox window tremble.
To avoid such tremble, you may make combobox invisible, then clear its children, append child, then make combobox visible.
hi,which version of ZK are you using?We use 3.6.1 and we do see that opening a combobox which already has an item selected makes the window scroll as if it sets focus on the combobox.Can anyone tell if code was modified to set focus on it onOpen? We dont see any such change in the code.Thanks!
Actually, I have the same problem as oda38 by using IE7.
The problem only be reproduced when scroll bar is shown in the browser.
First of all, select any item from the list. Then press DOWN arrow button on keyboard.
The window will put the combobox on the top of browser (for both IE7 and FF3) and the (horrible) scroll down effect will be appeared. (For IE7 only)
The following is the sample code to demonstrate the above issue.
<?page title="Combobox Testing" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Combobox Testing" border="normal">
<combobox id="cbbMain" autocomplete="false" autodrop="true">
<comboitem label="Apple" />
<comboitem label="Banana" />
<comboitem label="Cat" />
<comboitem label="Dog" />
<comboitem label="Egg" />
<comboitem label="Fox" />
<comboitem label="Girl" />
<comboitem label="Ham" />
</combobox>
<separator height="1000px" /> <!-- Show the vertical scroll bar -->
</window>
</zk>
P.S. I'm using ZK 3.6.1.
Asked: 2009-05-29 08:02:19 +0800
Seen: 1,210 times
Last updated: Jun 08 '09