[英]how to select a few continuous columns by pressing mouse and drag in jtable in java
我不分叉,现在使用“鼠标拖动”对我来说似乎很困难,所以我使用鼠标单击瞄准列 header 到 select ZC9FA155EA3AB5D652BD3FF5E397267C3 中的连续列下面的示例代码:
......
public int columnIndex=0 ; // for save column index
public SumDetail(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
sumTB.getTableHeader().addMouseListener(getTableHeaderMouseAdapter(sumTB));
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
......
columnIndex=tableModel.getRowCount()-1;
}
.....
// for clicking on column header to select column
protected MouseAdapter getTableHeaderMouseAdapter(final JTable table) {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int c = table.columnAtPoint(e.getPoint());
if(columnIndex>c){
table.clearSelection();
table.setColumnSelectionInterval(c, c);
}else{
table.setColumnSelectionInterval(columnIndex, c);
}
if (table.getRowCount() > 0) {
table.setRowSelectionInterval(0, table.getRowCount() - 1);
}
columnIndex=c;
if (table.isEditing()) {
table.getCellEditor().stopCellEditing();
}
}
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.