Example usage for javax.swing.table JTableHeader getDraggedDistance

List of usage examples for javax.swing.table JTableHeader getDraggedDistance

Introduction

In this page you can find the example usage for javax.swing.table JTableHeader getDraggedDistance.

Prototype

public int getDraggedDistance() 

Source Link

Document

Returns the column's horizontal distance from its original position, if and only if, a drag is in process.

Usage

From source file:SortableTable.java

/**
 * If the user is dragging or resizing, then we clear the sort column.
 *
 * @param e  the mouse event./*w ww .  ja  v a 2 s . c  o  m*/
 */
public void mouseDragged(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if ((header.getDraggedDistance() > 0) || (header.getResizingColumn() != null)) {
        this.renderer.setPressedColumn(-1);
        this.sortColumnIndex = -1;
    }
}

From source file:SortableTable.java

/**
 * Handle a mouse press event - if the user is NOT resizing a column and NOT dragging a column
 * then give visual feedback that the column header has been pressed.
 *
 * @param e  the mouse event./*w w w  . j a  v a 2s.c om*/
 */
public void mousePressed(final MouseEvent e) {

    final JTableHeader header = (JTableHeader) e.getComponent();

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (header.getDraggedDistance() < 1) { // dragging also takes precedence over sorting
            final int columnIndex = header.columnAtPoint(e.getPoint());
            final int modelColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
            if (this.model.isSortable(modelColumnIndex)) {
                this.sortColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex);
                this.renderer.setPressedColumn(this.sortColumnIndex);
                header.repaint();
                if (header.getTable().isEditing()) {
                    header.getTable().getCellEditor().stopCellEditing();
                }
            } else {
                this.sortColumnIndex = -1;
            }
        }
    }

}