I have a JTree and the Nodes are a abstract class (Item) that extends DefaultMutableTreeNode. I want to be able to select the node in the JTree, then have all the variables of the subclass of Item in a JTable, like in netbeans the properties editor and Navigator. I’m doing this in a swing environment, and not Netbeans module so the PropertyEditor looks nice but won’t work.
Share
If I understand you correctly you want to be able to display object property using generic way. The common answer to this question is to use reflection. You can discover your object and show as many properties as you want.
But in this case you will probably show properties that should not be shown to the user and are used by your program only.
I’d suggest to solve this problem using annotation. You can define your own annotation, e.g.
@DisplayablePropertyand mark all fields you wish to display on property editor using this annotation. Now you just have to check whether property is marked or not.This method is very flexible. Probably in future you will add parameters to this annotation like
view(TextField, CheckBox, Radio etc), format etc.