Object[][] cells = { {Boolean.FALSE, "必选", "1", ""}, {Boolean.FALSE,
"可选",
"", ""}, {Boolean.FALSE, "必选", "4", aba},
{Boolean.FALSE,
"可选", "8", ""}, {Boolean.FALSE, "必选", "", ""},
{Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE, "可选",
"",
""}, {Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE,
"可选",
"", ""}, {Boolean.FALSE, "必选", "", ""},
{Boolean.FALSE,
"可选", "", ""}, {Boolean.FALSE, "可选", "", ""}, {Boolean.FALSE, "必选",
"",
""}, {Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE, "必选", "", ""}, };
String[] columnNames = {"选择", "重要级", "文件名", "说明"}; DefaultTableModel model = new DefaultTableModel(cells, columnNames)
jTable1 = new JTable(model);
jTable1.getModel().addTableModelListener(new TableModelListener() {
boolean checked;
public void tableChanged(TableModelEvent e) {
String str = new String();
String SelectObj = ""; TableModel model = jTable1.getModel();
int count = model.getRowCount();
for (int i = 0; i < count; i++) {
checked = (Boolean) model.getValueAt(i, 0);
//SelectObj=new String();
if (checked) {
System.out.println(i); //输出选择项······
str = str + "" + String.valueOf(i) + ",";
SelectObj = SelectObj + "," +
(String) model.getValueAt(i, 1); System.out.println("获得行和列" + model.getColumnCount() +
"," + model.getRowCount());
String guanLian=(String)model.getValueAt(i,1);
System.out.println((String)model.getValueAt(i,2));
if(guanLian!=null||guanLian.length()<1){
model.setValueAt("1231312",i,1);
}
}
}
//objMyTable.editBol=checked;
this.isCellEditable(0,1);
System.out.println(str);
getAll = SelectObj;
System.out.println(SelectObj);
}
public boolean isCellEditable(int row, int column) {
return false;
}
});
我做了一个表格,里面含有Boolean类型的复选框,现在我想创建一个关联,比如说是当某行的第三列为8的时候·,那么在在当选择该行的时候,第八行也在同时被选择上···不知道该怎么实现··
请高手指点··
谢谢·····
"可选",
"", ""}, {Boolean.FALSE, "必选", "4", aba},
{Boolean.FALSE,
"可选", "8", ""}, {Boolean.FALSE, "必选", "", ""},
{Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE, "可选",
"",
""}, {Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE,
"可选",
"", ""}, {Boolean.FALSE, "必选", "", ""},
{Boolean.FALSE,
"可选", "", ""}, {Boolean.FALSE, "可选", "", ""}, {Boolean.FALSE, "必选",
"",
""}, {Boolean.FALSE, "必选", "", ""}, {Boolean.FALSE, "必选", "", ""}, };
String[] columnNames = {"选择", "重要级", "文件名", "说明"}; DefaultTableModel model = new DefaultTableModel(cells, columnNames)
jTable1 = new JTable(model);
jTable1.getModel().addTableModelListener(new TableModelListener() {
boolean checked;
public void tableChanged(TableModelEvent e) {
String str = new String();
String SelectObj = ""; TableModel model = jTable1.getModel();
int count = model.getRowCount();
for (int i = 0; i < count; i++) {
checked = (Boolean) model.getValueAt(i, 0);
//SelectObj=new String();
if (checked) {
System.out.println(i); //输出选择项······
str = str + "" + String.valueOf(i) + ",";
SelectObj = SelectObj + "," +
(String) model.getValueAt(i, 1); System.out.println("获得行和列" + model.getColumnCount() +
"," + model.getRowCount());
String guanLian=(String)model.getValueAt(i,1);
System.out.println((String)model.getValueAt(i,2));
if(guanLian!=null||guanLian.length()<1){
model.setValueAt("1231312",i,1);
}
}
}
//objMyTable.editBol=checked;
this.isCellEditable(0,1);
System.out.println(str);
getAll = SelectObj;
System.out.println(SelectObj);
}
public boolean isCellEditable(int row, int column) {
return false;
}
});
我做了一个表格,里面含有Boolean类型的复选框,现在我想创建一个关联,比如说是当某行的第三列为8的时候·,那么在在当选择该行的时候,第八行也在同时被选择上···不知道该怎么实现··
请高手指点··
谢谢·····
实现ListSelectionModel接口可能好处理。
你可以试一试。