Announcement Announcement Module
No announcement yet.
Newbie: autocompleting combobox example Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie: autocompleting combobox example

    Sorry for this basic question, but can anyone point me to a basic example of a combobox with autocompletion?

    Last edited by olorin; Jul 15th, 2010, 02:58 AM.

  • #2
    Hello, not sure if it is what you desired for because I am solving the same problem so here is what I have got

    public class CarForm extends AbstractForm{
    private List carTypes;

    protected JComponent createFormControl() {
    carTypes = carDao.getCarTypes();
    TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
    JComboBox box = new JComboBox(carTypes.toArray());
    formBuilder.add("carType", box);
    return formBuilder.getForm();

    Suppose the best way to accomplish that goal should be

    JComboBox box = getComponentFactory().createComboBox();

    but now I am lost


    • #3
      Sorry for not being clear. With an autocompleting combobox i mean a menu that is linked to a text field. If you type in the textfield, the combobox shows a subset starting with the same string (or gets positioned automatically at the location of a menu item starting with this string)


      • #4
        So lets make it right.

        In richclient-application-context do the following:

        <bean id="applicationServices" class="org.springframework.richclient.application. support.DefaultApplicationServices">
        <property name="formComponentInterceptorFactoryId">
        <idref bean="formComponentInterceptorFactory" />

        <bean id="formComponentInterceptorFactory"
        class="org.springframework.richclient.form.builder .support.ChainedInterceptorFactory">
        <property name="interceptorFactories">
        <bean class="org.springframework.richclient.list.ComboBo xAutoCompletionInterceptorFactory" />


        Now when I type h in the combobox textfield honda will be marked


        • #5
          Err.. does that work with the code you supplied?
          I had the app context settings allright.
          But, for starters, i can not start to type if i do not make my combobox editable.
          And then I would imagined that i would have needed to implement a listener of some sort to modify the menu upon typing.


          • #6
            But, for starters, i can not start to type if i do not make my combobox editable.
            And then I would imagined that i would have needed to implement a listener of some sort to modify the menu upon typing.

            I am not sure if we mean the same thing. I suppose you would like to acomplish this task. You must choose a value from the combobox menu. So you can click the arrow icon next to the combobox textfield and click the selected value or you start typing into the combobox textfield and only the values corresponding to the entered text will appear or will be marked. If it is so then that code I gave you is working. Suppose you already read it because there is a very few tutorials for rcp but check this pdf.


            In the opposite case try to describe it more specifically.


            • #7
              Thanks a lot marekto.
              The code I inherited was way more complex than your example with bindings, valueholders and comboboxes created separatly, and not working in harmony afterwards.
              (my combobox has contents that needs be reloaded from the db at times and it has a child combobox that needs to be updated when the selected value in my combobox changes).
              Starting from your example I got it working alright.
              Thanks a lot!!

              (FYI createFormControl Code now looks like this:
              // values refreshable from db
              orgList = new RefreshableValueHolder(new organizationValues(),
              ComboBoxBinding orgCBB = (ComboBoxBinding) bf.createBoundComboBox(
              orgCB = (JComboBox) formBuilder.add(orgCBB, "align=left")[1];
              // itemlistener updates child combobox
              orgCB.addItemListener(new orgCBListener());


              • #8
                you are welcome, Olorin. Glad I could help you. Also thanks for your example, very useful for me.