I don't split hairs,using the "mouse drag" seems difficult to me now, so i use mouse click the aiming column header to select the continuous columns in jtable.Sample code below:
......
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();
}
}
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.