Java Code Examples for javax.swing.table.JTableHeader#columnAtPoint()

The following examples show how to use javax.swing.table.JTableHeader#columnAtPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableSorter.java    From evosql with Apache License 2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {

            JTableHeader     h           = (JTableHeader) e.getSource();
            TableColumnModel columnModel = h.getColumnModel();
            int              viewColumn  = h.columnAtPoint(e.getPoint());
            int column = columnModel.getColumn(viewColumn).getModelIndex();

            if (column != -1) {
                int status = getSortingStatus(column);

                if (!e.isControlDown()) {
                    cancelSorting();
                }

                // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
                // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
                status = status + (e.isShiftDown() ? -1
                                                   : 1);
                status = (status + 4) % 3 - 1;    // signed mod, returning {-1, 0, 1}

                setSortingStatus(column, status);
            }
        }
 
Example 2
Source File: SortableTableHeaderListener.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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.
 */
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;
            }
        }
    }

}
 
Example 3
Source File: TableEditorPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void selectColumn( final JTableHeader aTableHeader, final Point aPoint ) {
  try {
    selectingHeaderColumn = true;

    final TableColumnModel columnModel = table.getColumnModel();
    final int columnIndex = aTableHeader.columnAtPoint( aPoint );
    if ( columnIndex <= 0 ) {
      return;
    }

    final TableColumn tableColumn = columnModel.getColumn( columnIndex );

    table.clearSelection();
    table.setColumnSelectionInterval( columnIndex, columnIndex );
    table.setSelectedColumn( tableColumn );
    if ( table.getRowCount() > 0 ) {
      table.addRowSelectionInterval( 0, table.getRowCount() - 1 );
    }
  } finally {
    selectingHeaderColumn = false;
  }
}
 
Example 4
Source File: OptionsAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mouseClicked (MouseEvent evt) {
    Component c = evt.getComponent ();
    if (c instanceof JTableHeader) {
        JTableHeader h = (JTableHeader)c;
        
        // show/hide additional properties
        if (1 == h.columnAtPoint (evt.getPoint ())) {
            refreshColumns (true);
        }
    }
}
 
Example 5
Source File: TableColumnManager.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void checkForPopup(MouseEvent e)
{
	if (e.isPopupTrigger())
	{
		JTableHeader header = (JTableHeader)e.getComponent();
		int column = header.columnAtPoint( e.getPoint() );
		showPopup(column);
	}
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void show(Component c, int x, int y) {
  if (c instanceof JTableHeader) {
    JTableHeader header = (JTableHeader) c;
    header.setDraggedColumn(null);
    header.repaint();
    header.getTable().repaint();
    index = header.columnAtPoint(new Point(x, y));
    if (index >= 0) {
      super.show(c, x, y);
    }
  }
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void show(Component c, int x, int y) {
  if (c instanceof JTableHeader) {
    JTableHeader header = (JTableHeader) c;
    header.setDraggedColumn(null); // bookmark_1
    // if (header.getDraggedColumn() != null) remain dirty area >>>
    header.repaint();
    header.getTable().repaint();
    // <<<
    index = header.columnAtPoint(new Point(x, y));
    super.show(c, x, y);
  }
}
 
Example 8
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void mousePressed(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  int idx = h.columnAtPoint(e.getPoint());
  if (idx < 0) {
    return;
  }
  TableColumnModel m = h.getColumnModel();
  Object title = m.getColumn(idx).getHeaderValue();
  cardLayout.show(contentsPanel, Objects.toString(title));
  selectedColumn = title;
}
 
Example 9
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private void updateRolloverColumn(MouseEvent e) {
  JTableHeader h = (JTableHeader) e.getComponent();
  if (Objects.isNull(h.getDraggedColumn()) && h.contains(e.getPoint())) {
    int col = h.columnAtPoint(e.getPoint());
    if (col != rolloverColumn) {
      // int oldRolloverColumn = rolloverColumn;
      rolloverColumn = col;
      // rolloverColumnUpdated(oldRolloverColumn, rolloverColumn);
    }
  }
}