如何将渲染器设置为jtable上的复选框为行? [英] how to set renderer to checkbox on jtable for row?
问题描述
-
我使用以下代码将渲染器设置为jtable上的复选框
I set the renderer to the checkbox on jtable using following code
Object[] ColumnData = {"Sr No","Ward Name","Total voters","Action"};
Object[][] RawData=null;
//循环
model.insertRow(x,new Object [] {key,ward_name_var,total_vot_var,new Object [] {o}});
model.setValueAt(o,x,3);
tblWard.setModel(model);
model.insertRow(x, new Object[]{ key,ward_name_var,total_vot_var,new Object[]{o}}); model.setValueAt(o,x,3); tblWard.setModel(model);
Setchk(tblWard,3,checkbox); //通过调用包含以下内容的该方法
Setchk(tblWard,3,checkbox); // by calling this method which contains following
私有无效Setchk(JTable jTable1,int i,JCheckBox复选框)
{
jTable1.getColumnModel( ).getColumn(i).setCellRenderer((new CWCheckBoxRenderer()));
jTable1.getColumnModel()。getColumn(i).setCellEditor(new CheckBoxCellEditor());
}
private void Setchk(JTable jTable1, int i, JCheckBox checkbox) { jTable1.getColumnModel().getColumn(i).setCellRenderer((new CWCheckBoxRenderer())); jTable1.getColumnModel().getColumn(i).setCellEditor(new CheckBoxCellEditor()); }
Blockquote
Blockquote
我们如何尝试在行上设置jtable的复选框。
预先表示感谢。
how can we try it for row to set the checkbox on jtable. thanks in advance.
推荐答案
如果您的数据类型为 Boolean.class
,默认渲染将显示一个复选框。要更改特定行中的复选框,您需要相应的 CellEditor
。默认的渲染器/编辑器在此处使用;自定义组件在此处中进行了说明。
If your data is of type Boolean.class
, the default render will display a checkbox. To change the checkbox in a particular row, you need a corresponding CellEditor
. The default render/editor are used here; custom components are illustrated here.
这篇关于如何将渲染器设置为jtable上的复选框为行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!