[英]Multiple row selection on click
I was wondering if the following case is possible with jtable: 我想知道jtable是否可能出现以下情况:
R4 and R6 are "sub rows" and they reference R1, so whenever I click on R1, it should auto-select R4 and R6. R4和R6是“子行”,它们引用R1,因此每当我单击R1时,它都应自动选择R4和R6。
Yes, it's possible. 是的,有可能。 This is a very basic 'hacky' example which should give you enough information about the method calls involved. 这是一个非常基本的“ hacky”示例,它应为您提供有关所涉及的方法调用的足够信息。 This will select row 3 & 5 whenever you select row 1: 只要您选择第1行,就会选择第3行和第5行:
// jt is a JTable defined at class level for handle visibility
jt = new JTable() {
@Override
public void valueChanged(ListSelectionEvent e) {
super.valueChanged(e);
if(e.getValueIsAdjusting()) return;
if(jt.getSelectedRow() == 1 && jt.getSelectedRows().length == 1) {
ListSelectionModel lsm = jt.getSelectionModel();
lsm.addSelectionInterval(3, 3);
lsm.addSelectionInterval(5, 5);
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.