[英]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.