Java Code Examples for javax.swing.table.JTableHeader#getResizingColumn()
The following examples show how to use
javax.swing.table.JTableHeader#getResizingColumn() .
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: SortableTableHeaderListener.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * 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 2
Source File: SortableTableHeaderListener.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * When the user releases the mouse button, we attempt to sort the table. * * @param e the mouse event. */ 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(); } } }
Example 3
Source File: SortableTableHeaderListener.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * If the user is dragging or resizing, then we clear the sort column. * * @param e the mouse event. */ 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; } }
Example 4
Source File: ProfilerTable.java From netbeans with Apache License 2.0 | 4 votes |
public void doLayout() { ProfilerColumnModel cModel = _getColumnModel(); JTableHeader header = getTableHeader(); TableColumn res = header == null ? null : header.getResizingColumn(); if (res != null) { // Resizing column int delta = getWidth() - cModel.getTotalColumnWidth(); TableColumn next = cModel.getNextVisibleColumn(res); if (res == next) { res.setWidth(res.getWidth() + delta); } else { next.setWidth(next.getWidth() + delta); } } else { // Resizing table int toResizeIndex = cModel.getFitWidthColumn(); if (toResizeIndex == -1) { super.doLayout(); } else { Enumeration<TableColumn> columns = cModel.getColumns(); TableColumn toResizeColumn = null; int columnsWidth = 0; while (columns.hasMoreElements()) { TableColumn column = columns.nextElement(); if (column.getModelIndex() == toResizeIndex) { if (!cModel.isColumnVisible(column)) { super.doLayout(); return; } toResizeColumn = column; } else { columnsWidth += column.getWidth(); } } if (toResizeColumn != null) toResizeColumn.setWidth(getWidth() - columnsWidth); // instead of super.doLayout() layout(); } } }
Example 5
Source File: ProfilerTable.java From visualvm with GNU General Public License v2.0 | 4 votes |
public void doLayout() { ProfilerColumnModel cModel = _getColumnModel(); JTableHeader header = getTableHeader(); TableColumn res = header == null ? null : header.getResizingColumn(); if (res != null) { // Resizing column int delta = getWidth() - cModel.getTotalColumnWidth(); TableColumn next = cModel.getNextVisibleColumn(res); if (res == next) { res.setWidth(res.getWidth() + delta); } else { next.setWidth(next.getWidth() + delta); } } else { // Resizing table int toResizeIndex = cModel.getFitWidthColumn(); if (toResizeIndex == -1) { super.doLayout(); } else { Enumeration<TableColumn> columns = cModel.getColumns(); TableColumn toResizeColumn = null; int columnsWidth = 0; while (columns.hasMoreElements()) { TableColumn column = columns.nextElement(); if (column.getModelIndex() == toResizeIndex) { if (!cModel.isColumnVisible(column)) { super.doLayout(); return; } toResizeColumn = column; } else { columnsWidth += column.getWidth(); } } if (toResizeColumn != null) toResizeColumn.setWidth(getWidth() - columnsWidth); // instead of super.doLayout() layout(); } } }