Combo Box

From Apache OpenOffice Wiki
Jump to: navigation, search

A combo box control presents a list of items to the user. It also contains a text field allowing the user to input text that is not in the list. A combo box is used when there is a list of suggested choices, whereas a list box is used when the user's input is limited only to the list. The features and properties of a combo box and a list box are similar. As can be seen in the combo box includes the functionality of a, which also allows you to add an to the combo box. The text displayed in the field of the combo box can be controlled by the Text property of the combo box model that supports the service Just like in the list box, the actual list of items is accessible through the StringItemList property. A useful feature of the model is the automatic word completion that can be activated by setting the property Autocomplete to true.

You can control the items in a combo box via the interface at the control, which offers a more convenient access to the control's functionality.

  public XComboBox insertComboBox(int _nPosX, int _nPosY, int _nWidth){
  XComboBox xComboBox = null;
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "ComboBox");
      String[] sStringItemList = new String[]{"First Entry", "Second Entry", "Third Entry", "Fourth Entry"};
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oComboBoxModel = m_xMSFDialogModel.createInstance("");
      XMultiPropertySet xCbBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oComboBoxModel);
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order!
      new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "StringItemList", "Width" } ,
      new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), sStringItemList, new Integer(_nWidth)}); 
      // The following property may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration 
      XPropertySet xCbBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCbBModelMPSet);
      xCbBModelPSet.setPropertyValue("MaxTextLen", new Short((short) 10));
      xCbBModelPSet.setPropertyValue("ReadOnly", Boolean.FALSE);
      // add the model to the NameContainer of the dialog model
      m_xDlgModelNameContainer.insertByName(sName, xCbBModelMPSet);
      XControl xControl = m_xDlgContainer.getControl(sName);
      // retrieve a ListBox that is more convenient to work with than the Model of the ListBox...
      xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, xControl);
  }catch ( ex){
      /* perform individual exception handling here.
       * Possible exception types are:
      return xComboBox;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages