Enum properties

Here is another one on which the vision of the three eyed raven is obscure:

In the bean info class how do you set an enum property. I tried setting the “dropMode” property as an int, but that didn’t work. In Designer, the property was blank and wouldn’t allow me enter a value.
The following incantation is illegal:

addEnumProp("dropMode", "Drop Mode", "Options: default, on, insert and “on and insert”", CAT_DATA, new DropMode[] {DropMode.USE_SELECTION, DropMode.ON, DropMode.INSERT, DropMode.ON_OR_INSERT}, new String[]{"default", "on", "insert", "on and insert"});
So what’s the required spell?

According to the signature, you can’t have an actual enum type property. The property needs to expose int getters and setters, and supply the values in addEnumProp() as integers. How you actually store the selected value is up to you, of course.

Yep that works, thanks.

I’m using the following in the bean info class:

addEnumProp("dropMode", "Drop Mode", "Options: default, on, insert and 'on and insert'", CAT_DATA, new int[] {DropMode.USE_SELECTION.ordinal() , DropMode.ON.ordinal() , DropMode.INSERT.ordinal() , DropMode.ON_OR_INSERT.ordinal()}, new String[]{"default", "on", "insert", "on and insert"});
With the following to translate the integer back to an enum:

private void updateDropMode() { Integer val = DropMode.USE_SELECTION.ordinal(); if (baseDropMode != null) { val = baseDropMode; } for (DropMode d : DropMode.values()) { if (d.ordinal() == val) { jtree.setDropMode(d); } } }

Internet suggests that use of the ordinal function is not kosher. Better suggestions?

[quote=“JimBranKelly”]Internet suggests that use of the ordinal function is not kosher. Better suggestions?[/quote]I wouldn’t worry too much. The issue is that ordinals are potentially subject to change, and your component will be serialized/deserialized with the integers. Future versions could mess up a project from an older version, simply by a difference in the underlying version of JFreeChart.
The canonical solution would be to use a switch statement in both getter and setter with each value called out.