从 Jtable 中制作 PropertyEditor
我有一个 JTree,节点是一个扩展 DefaultMutableTreeNode 的抽象类 (Item)。我希望能够选择 JTree 中的节点,然后将 Item 子类的所有变量放在 JTable 中,就像 netbeans 中的属性编辑器和导航器一样。我是在 swing 环境中执行此操作,而不是 Netbeans 模块,因此 PropertyEditor 看起来不错,但无法工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您希望能够使用通用方式显示对象属性。这个问题的常见答案是使用反射。您可以发现您的对象并显示任意数量的属性。
但在这种情况下,您可能会显示不应向用户显示且仅供您的程序使用的属性。
我建议使用注释来解决这个问题。您可以定义自己的注释,例如
@DisplayableProperty
,并使用此注释标记您希望在属性编辑器上显示的所有字段。现在您只需检查属性是否已标记。这种方法非常灵活。将来您可能会向此注释添加参数,例如视图(TextField、CheckBox、Radio 等)、格式等。
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.
@DisplayableProperty
and 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.