hide UserField Tom Schindl Fabricio Lemos Stephan Wunderlich How can I hide a UserField

I'm trying to hide a UserField programmatically but could not find a property to set

You to set the IsVisible-property of the field to False

import {%see com.sun.star.beans.PropertyVetoException}; import {%see com.sun.star.beans.UnknownPropertyException}; import {%see com.sun.star.beans.XPropertySet}; import {%see com.sun.star.container.NoSuchElementException}; import {%see com.sun.star.container.XEnumeration}; import {%see com.sun.star.container.XEnumerationAccess}; import {%see com.sun.star.lang.IllegalArgumentException}; import {%see com.sun.star.lang.WrappedTargetException}; import {%see com.sun.star.lang.XComponent}; import {%see com.sun.star.text.XDependentTextField}; import {%see com.sun.star.text.XTextFieldsSupplier}; import {%see com.sun.star.uno.UnoRuntime}; public class HideFieldSnippet { public void hideField(XComponent component, String fieldName ) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException, PropertyVetoException, IllegalArgumentException { // Get Access to the TextFields in the document XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier)UnoRuntime.queryInterface(XTextFieldsSupplier.class, component); XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields(); XEnumeration enumeration = xEnumeratedFields.createEnumeration(); boolean changed = false; // Loop through the TextFields and search for the right field while (enumeration.hasMoreElements() && !changed) { Object field = enumeration.nextElement(); XDependentTextField dependentTextField = (XDependentTextField)UnoRuntime.queryInterface(XDependentTextField.class, field); XPropertySet propertySet = dependentTextField.getTextFieldMaster(); String name = (String) propertySet.getPropertyValue("Name"); if (name.equals(fieldName)) { XPropertySet fieldProperties = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); fieldProperties.setPropertyValue("IsVisible", Boolean.FALSE); changed = true; } } } }
Initial version