我有一个 JTable,它是使用表模型从数据结构加载的。数据结构的格式为 NavigableMap>
。示例数据是
Table Format:
Range f1,v1 f2,v2 f3,v3 f4,v4
12.1-30.2 30,true 32,false 45,true 50,false
30.2-45.6 30,true 32.4,true 45,true 50.1,true
:上面的数据格式在 DS 中表示,因为
DS Format:
Key Value
12.1 <<30,true>,<32,false>,<45,true>,<50,false>>
30.2 <<30,true>,<32.4,true>,<45,true>,<50.1,true>>
45.6 null
我已经设法使用表模型在 Jtable 中表示上面给定的数据。一旦数据从 DS 加载到表中,我必须允许用户编辑。现在这就是我遇到问题的地方.我的疑问是是否应该使数据结构与表中的更改保持同步,或者我应该在用户完成编辑后从表中重新创建DS,然后将其替换为旧的。
更重要的是,我需要验证数据(例如上面的例子 - 假设用户想要编辑值 30.1。他应该只被允许输入 12.1 和 45.6 之间的值。因为数据表是字符串的(一旦加载)我计划使用正则表达式和按键侦听器并消耗与正则表达式和不在范围内的值不匹配的所有用户按键。我不确定这是一个好主意还是有什么影响。我会希望得到一些关于这方面的建议。
I have a JTable which is loaded from a data-structure using table model.The data-structure is of the format NavigableMap<Float,NavigableMap<Float,Boolean>>
.An example data is:
Table Format:
Range f1,v1 f2,v2 f3,v3 f4,v4
12.1-30.2 30,true 32,false 45,true 50,false
30.2-45.6 30,true 32.4,true 45,true 50.1,true
The above data format is represented in the DS as
DS Format:
Key Value
12.1 <<30,true>,<32,false>,<45,true>,<50,false>>
30.2 <<30,true>,<32.4,true>,<45,true>,<50.1,true>>
45.6 null
I have managed to represent the above given data in Jtable using table-model.Once the data is loaded from the DS to the table I have to allow user edit.Now this is where I have problem.My doubt is whether is should keep the data structure synchronized with the changes in the table or should i recreate the DS from the table once the user finish editing and then replace it with the old one.
More over I need to validate the data(for example from above - Suppose the user want's to edit the value 30.1.He should only be allowed to enter values between 12.1 and 45.6.Since data the tables are string's (once loaded) I'm planning to use regex and key-listener and consume all user key presses which doesn't match the regex and values which doesn't come within the range.I'm not sure is this is a good idea or what are implications.I would like to get some suggestions on this.
发布评论
评论(1)
一旦用户完成编辑表格,我将重新创建您的 DS。
您始终可以创建自定义编辑器来显示弹出对话框,其中对于范围内的每个值都有两个单独的文本字段。然后,您可以将每个字段编辑为指定范围内的双精度值,并在将其保存到模型之前重新创建格式化字符串。这是我准备的一个旧示例,可以帮助您入门:
I would recreate your DS once the user is finised editing the table.
You can always create a custom editor to display a popup dialog where you have two separate text fields for each value of the range. Then you can edit each field as a double value within your specified range and recreate the formatted string before saving it to the model. Here's an old example I have lying around to get you started: