1

ContolsFX example for PropertySheet have several options. First, create a bean with beaninfo. In this case I can't set category for each field in PropertySheet. I can choose only between basic and expert categories. Second option is to use Map, where I can set category for each field. But I want to use beans. Is it possible to set category for bean fields?

public class SampleBeanBeanInfo extends SimpleBeanInfo {

    private static final BeanDescriptor beanDescriptor = new BeanDescriptor(SampleBeanBeanInfo.class);
    private static PropertyDescriptor[] propDescriptors;

    static {
        beanDescriptor.setDisplayName("Sample Bean");
    }

    @Override
    public BeanDescriptor getBeanDescriptor() {
        return beanDescriptor;
    }

    @Override
    public int getDefaultPropertyIndex() {
        return 0;
    }

    @Override
    public PropertyDescriptor[] getPropertyDescriptors() {
        if (propDescriptors == null) {
            propDescriptors = new PropertyDescriptor[5];
            try {
                CustomPropertyDescriptor cdp = new CustomPropertyDescriptor("id", SampleBean.class, "getId", "setId");
                cdp.setDisplayName("Id");
                cdp.setEditable(false);
                propDescriptors[0] = cdp;
                propDescriptors[1] = new PropertyDescriptor("firstName", SampleBean.class, "getFirstName", "setFirstName");
                propDescriptors[1].setDisplayName("First Name");
                propDescriptors[2] = new PropertyDescriptor("lastName", SampleBean.class, "getLastName", "setLastName");
                propDescriptors[2].setDisplayName("Last Name");
                propDescriptors[3] = new PropertyDescriptor("address", SampleBean.class, "getAddress", "setAddress");
                propDescriptors[3].setDisplayName("Address");
                propDescriptors[3].setPropertyEditorClass(PopupPropertyEditor.class);
                propDescriptors[4] = new PropertyDescriptor("hiddenValue", SampleBean.class, "getHiddenValue", "setHiddenValue");
                propDescriptors[4].setDisplayName("Hidden Value");
                propDescriptors[4].setHidden(true);
            } catch (IntrospectionException ex) {
                ex.printStackTrace();
            }
        }
        return propDescriptors;
    }

}
fabian
  • 80,457
  • 12
  • 86
  • 114
Korvin Gump
  • 383
  • 4
  • 7

2 Answers2

1

After investigation, i found that categories are hardcoded and could not be changed when we are using beans. So you should use your custom PropertySheet.Item implementation. In this case we can set any category name for properties. Check out official example in controlsFX project how to do it.

Korvin Gump
  • 383
  • 4
  • 7
0

Try:

propDescriptors[i].setValue(org.controlsfx.property.BeanProperty.CATEGORY_LABEL_KEY, "Your category name");
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • We usually prefer more explanation, not just a code dump. What is the key thing of your solution? – Robert Sep 17 '16 at 13:45
  • Simply according to the source code of BeanProperty.java: @Override public String getCategory() { String category = (String) this.beanPropertyDescriptor.getValue(BeanProperty.CATEGORY_LABEL_KEY); – Chen Shi Sep 19 '16 at 12:13