Combobox scroll selection into view

asked 2013-03-22 16:59:27 +0800

kbsimm gravatar image kbsimm

How does one cause an item matching typed in characters of a combobox to scroll into view?

Details: In relation to an earlier question I asked, AutoCompleteComboBox..., I am attempting to use a Combobox and ListModelList as follows:

  1. The user will type one or more characters into the Combobox.
  2. The Combobox will perform what is typically known as type ahead or autocomplete.
  3. The matching value will be displayed in the Combobox's textbox.
  4. The Combobox's list will scroll to the matching value.

1 thru 3 work fine but 4 does not. That is the Combobox does not scroll to the matching item.

I would expect the scrolling to be on the Combobox but looking at javadocs ListModelList has a fireSelectionEvent which speaks of the ability to scroll into view. Or rather it speaks of the default which is not to scroll into view and provides no convenient method to change that. I find it odd that scrolling is on the model not the UI element, Combobox.

I have found the static Client.scrollIntoView(Component cmp) which I attempted as

Combobox c = new Combobox();
c.addEventListener(Events.ON_CHANGING, new EventListener<InputEvent>(){
  public void onEvent(InputEvent event) throws Exception {

But that does not work.

Help is appreciated. Thank you

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-04-03 08:26:10 +0800

Darksu gravatar image Darksu
1991 1 4

Hello kbsimm,

The following example worked:


    <window border="none" apply="pkg$.MasterDetailComposer">
        <combobox id="c" autodrop="true"/>


package pkg$;

import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.InputEvent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Window;

public class MasterDetailComposer extends GenericForwardComposer<Window> {

    Combobox c;

    private static final long serialVersionUID = 748611244810222881L;

    public void doAfterCompose(Window comp) throws Exception {

        ListModelList<String> itemsListModelList = new ListModelList<>();

        c.addEventListener(Events.ON_CHANGING, new EventListener<InputEvent>(){
          public void onEvent(InputEvent event) throws Exception {

Best Regards,


link publish delete flag offensive edit

answered 2019-08-07 02:35:51 +0800

vince1101 gravatar image vince1101

you are using "c.getSelectedItem()" but the selected item of the combobox is not set until actually selected, the scroll keeps going to the old value of the combobox and not the currently suggested value while typing if using the getSelectedItem()... do you have another property of the combobox that would return the currently suggested item of the list ?

link publish delete flag offensive edit


please just create one new question, instead of reopening 3 old threads!

cor3000 ( 2019-08-07 10:39:26 +0800 )edit

sure, already did, but people that had this issue 3 years ago may still active, or not... and receiving a notification that the extact same thing is trying to be done unsucessfully, by someone else might motivate them to conect

vince1101 ( 2019-08-07 11:43:58 +0800 )edit

if your intention is to draw attention, my recommendation is to start a new thread with your new or similar question, and then add comments to existing threads linking to your new thread. Like this the threads don't get too long and keep their focus on the solution based on the old version back then

cor3000 ( 2019-08-07 12:59:01 +0800 )edit

I increased your karma again so you can add clickable links... I hope this helps

cor3000 ( 2019-08-07 13:01:30 +0800 )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




Asked: 2013-03-22 16:59:27 +0800

Seen: 59 times

Last updated: Aug 07 '19

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