Example usage for javax.swing.table JTableHeader getResizingColumn

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

Introduction

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

Prototype

public TableColumn getResizingColumn() 

Source Link

Document

Returns the resizing column.

Usage

From source file:SortableTable.java

/**
 * When the user releases the mouse button, we attempt to sort the table.
 *
 * @param e  the mouse event./*  w ww .  j av  a 2  s.c o m*/
 */
public void mouseReleased(final MouseEvent e) {

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

    if (header.getResizingColumn() == null) { // resizing takes precedence over sorting
        if (this.sortColumnIndex != -1) {
            final SortableTableModel model = (SortableTableModel) header.getTable().getModel();
            final boolean ascending = !model.isAscending();
            model.setAscending(ascending);
            model.sortByColumn(this.sortColumnIndex, ascending);

            this.renderer.setPressedColumn(-1); // clear
            header.repaint();
        }
    }
}

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.//www  . j  a va 2s  .c  o  m
 */
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;
            }
        }
    }

}

From source file:SortableTable.java

/**
 * If the user is dragging or resizing, then we clear the sort column.
 *
 * @param e  the mouse event./*from  w ww.  java 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;
    }
}