摆动数据对象的编辑器,最简单的方法是什么?

时间:2021-10-25 14:04:54

I have a java object with several members. I want to create a small, quick and dirty editor that allows me to set the value of the members in an easy way. I've created a Panel that contains a TextField for every member. I have a setValues() method that will take the value of the TextFields and set them into the object. This method is automatically invoked when I call getDataObject() from the panel. Some of the members contain Strings, some others are doubles and some are integers. Nothing fancy.

我有一个有几个成员的java对象。我想创建一个小而快速且脏的编辑器,允许我以简单的方式设置成员的值。我创建了一个Panel,其中包含每个成员的TextField。我有一个setValues()方法,它将获取TextFields的值并将它们设置为对象。当我从面板调用getDataObject()时,会自动调用此方法。一些成员包含字符串,一些其他是双打,一些是整数。没有什么花哨。

The question is, however, what would be the easier way to improve this Panel? How can I add some validation without having to manually check every value? How can I do this without having to write a huge amount of code? At the moment my quick and very dirty implementation just propagates the RuntimeException, but of course this is only temporary.

但问题是,改进该小组的更简单方法是什么?如何在不必手动检查每个值的情况下添加一些验证?如何在不写大量代码的情况下完成此操作?目前,我的快速且非常脏的实现只传播RuntimeException,但当然这只是暂时的。

Before I set myself to write all this code, I wondered what would be the best pattern, or if there is some library available to perform such operations, as this seems to be a relatively commmon use case. In other words, if there is a lazy way out.

在我自己编写所有这些代码之前,我想知道什么是最好的模式,或者是否有一些库可以执行这样的操作,因为这似乎是一个相对常见的用例。换句话说,如果有一种懒惰的出路。

2 个解决方案

#1


1  

Quihubole Mario! :)

Quihubole Mario! :)

I've read sometime ago about this library from JGoodies, but to be honest I don't know if it is related or not.

我刚才读过JGoodies的这个图书馆,但说实话我不知道它是否相关。

JGoodies Binding

Take a look at it and see if it helps.

看看它,看看它是否有帮助。

#2


1  

Take a look at property editor at http://www.l2fprod.com/common/

请访问http://www.l2fprod.com/common/查看属性编辑器

#1


1  

Quihubole Mario! :)

Quihubole Mario! :)

I've read sometime ago about this library from JGoodies, but to be honest I don't know if it is related or not.

我刚才读过JGoodies的这个图书馆,但说实话我不知道它是否相关。

JGoodies Binding

Take a look at it and see if it helps.

看看它,看看它是否有帮助。

#2


1  

Take a look at property editor at http://www.l2fprod.com/common/

请访问http://www.l2fprod.com/common/查看属性编辑器