Currency Field

From Apache OpenOffice Wiki
Jump to: navigation, search

The currency field control can be considered a specialization of the It is used for entering and displaying currency values. In addition to the currency value, reflected by the property Value, a currency symbol, set by the CurrencySymbol property, is displayed. If the PrependCurrencySymbol property is set to true, the currency symbol is displayed in front of the currency value.

  public XTextComponent insertCurrencyField(XTextListener _xTextListener, int _nPositionX, int _nPositionY, int _nWidth){
  XTextComponent xTextComponent = null;
      // create a unique name by means of an own implementation...
      String sName = createUniqueName(m_xDlgModelNameContainer, "CurrencyField");
      // create a controlmodel at the multiservicefactory of the dialog model... 
      Object oCFModel = m_xMSFDialogModel.createInstance("");
      XMultiPropertySet xCFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel);
      // Set the properties at the model - keep in mind to pass the property names in alphabetical order! 
      new String[] {"Height", "Name", "PositionX", "PositionY", "Width"},
      new Object[] { new Integer(12), sName, new Integer(_nPositionX), new Integer(_nPositionY), new Integer(_nWidth)});
      // The controlmodel is not really available until inserted to the Dialog container 
      m_xDlgModelNameContainer.insertByName(sName, oCFModel);
      XPropertySet xCFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oCFModel);
      // The following properties may also be set with XMultiPropertySet but we
      // use the XPropertySet interface merely for reasons of demonstration
      xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Boolean.TRUE);
      xCFModelPSet.setPropertyValue("CurrencySymbol", "$");
      xCFModelPSet.setPropertyValue("Value", new Double(2.93));
      // add a textlistener that is notified on each change of the controlvalue...
      Object oCFControl = m_xDlgContainer.getControl(sName);
      xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, oCFControl);
  }catch ( ex){
      /* perform individual exception handling here.
       * Possible exception types are:
      return xTextComponent;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages