在 DefaultTableModel 中插入单选按钮
我有一个 2D 对象数组,需要通过扩展 DefaultTableModel 的表模型类在表中显示。除了容纳该数组中包含的数据所需的列之外,我还想添加一个带有单选按钮的额外列,以便用户能够进行选择。由于表格模型仅接受对象或向量数组,我应该如何添加单选按钮?
I have a 2D array of objects which needs to be displayed in a table through a table model class which extends a DefaultTableModel. In addition to the columns needed to accommodate the data included in this array, I would like to add an extra column with radiobuttons, in order to enable the user to make a selection. As table model accepts only arrays of objects or vectors, how should I add radio buttons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
JTable
推断如何根据条目的类呈现和编辑条目,如教程文章 编辑器和渲染器。在此示例中,复选框允许在一列中进行多项选择。替换单选按钮并使用ButtonGroup< /code>
将容纳独特的选择。
By default,
JTable
infers how to render and edit entries based on the entry's class, as discussed in the tutorial article Editors and Renderers. In this example, a checkbox allows multiple selections in a column. Substituting a radio button and using aButtonGroup
would accommodate a unique selection.