/**
  * Implemented to do some tweaks/bookkeeping before/after passing the event to the original
  *
  * <p>- temporarily disallow reordering if hit on first column - calculate the max mouseX that's
  * allowable in dragging to the left
  */
 @Override
 public void mousePressed(MouseEvent e) {
   int index = header.columnAtPoint(e.getPoint());
   boolean reorderingAllowed = header.getReorderingAllowed();
   if (index == 0) {
     // temporarily disable re-ordering
     header.setReorderingAllowed(false);
   }
   mouseDelegate.mousePressed(e);
   header.setReorderingAllowed(reorderingAllowed);
   if (header.getDraggedColumn() != null) {
     Rectangle r = header.getHeaderRect(index);
     maxX = header.getColumnModel().getColumn(0).getWidth() + e.getX() - r.x - 1;
   }
 }
Exemplo n.º 2
0
    /**
     * ***************************************************************************
     *
     * @param event
     */
    public void mouseReleased(MouseEvent event) {
      int sortColumn;
      JTableHeader tableHeader;
      Point mouseLocation;
      Rectangle columnHeaderArea;

      m_sortAscending = !m_sortAscending;
      mouseLocation = event.getPoint();
      tableHeader = getTableHeader();
      sortColumn = tableHeader.columnAtPoint(mouseLocation);

      if (sortColumn >= 0) {
        // When the cursor is resizing a column, the mouse released event will
        // reach here.  To prevent sorting happening during resizing, the column
        // header area is inset on the left and right by 10 pixels each.
        columnHeaderArea = tableHeader.getHeaderRect(sortColumn);
        columnHeaderArea.x -= 10;
        columnHeaderArea.width -= 20;

        if (columnHeaderArea.contains(mouseLocation)) {
          sort(sortColumn, m_sortAscending);
        }
      }
    }