用于输入配对序列的 Swing 组件
我有一个Java应用程序,我需要一个用户友好的组件来轻松输入很多对,我认为最友好的方法是制作一个表格,有点像电子表格,让他们手动编辑,但我'我不确定要使用什么侦听器,而且看起来相当复杂,我想知道是否有更好的组件可以完成该任务。
I have a Java application, and I need an user-friendly component for entering a lot of pairs easily, I think the most friendly way to do it is make a table, somewhat like a spreadsheet and let them edit that manually, but i'm not sure what listeners to use for that, and it seems rather complicated, what I want to know is if there is a nicer component for that task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 JTable。您可以编写一个扩展 AbstractTableModel 处理显示、验证等。它会为您处理大部分工作。您只需要重写您关心的几个方法即可。 关于表的 Java 教程 有一个非常好的概述,但要使单元格可编辑,您几乎需要做的就是让 isCellEditable() 返回 true 并实现适当的 setValueAt() 函数。
I would use a JTable. You can write a class which extends AbstractTableModel to handle display, validation, etc. It handles most of the work for you. You just need to override the few methods you care about. The Java tutorial on Tables has a pretty good overview, but pretty much all you need to do to make your cells editable is have isCellEditable() return true and implement an appropriate setValueAt() function.