com.jidesoft.grid
Class SortableTable
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
com.jidesoft.grid.JideTable
com.jidesoft.grid.ContextSensitiveTable
com.jidesoft.grid.NavigableTable
com.jidesoft.grid.CellStyleTable
com.jidesoft.grid.CellSpanTable
com.jidesoft.grid.CategorizedTable
com.jidesoft.grid.SortableTable
- All Implemented Interfaces:
- IndexChangeListener, SortListener, TableAdapter, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable
- Direct Known Subclasses:
- AggregateTable, FeedTable, HierarchicalTable, NavigationSortableTable, TreeTable
public class SortableTable
- extends CategorizedTable
- implements SortListener
SortableTable
is a table which uses SortableTableModel
so that multiple columns can be
sorted. If user presses mouse key on the table column header, the corresponding table column will be sorted. The
first click will sort ascendingly, the second click to sort descendingly, and the third click to reset back to
unsorted mode.
Difference from other implementation of SortableTable, it can do multiple column sorting. Just press CTRL key (or
Command key on Mac OS X) and hold, click several column headers will sort by all of them. The column header will show
a small number to indicate which one is first sort-by column, second sort-by column etc.
SortableTable
can accept any table model as input. However it doesn't change anything in the table model
whens sorting. A new instance of SortableTableModel is created when setModel is called to wrap around the actual
table model.
new SortableTableModel(model)
If you call sortableTableModel.getModel(), this SortableTableModel instance will be returned if the table is
sortable. If you want to get the actual table model you created, call ((TableModelWrapper)
getModel()).getActualModel(). If you use several levels of TableModelWrappers, you may want to use TableModelWrapperUtils.getActualTableModel(javax.swing.table.TableModel, Class)
to find the inner most table model.
Since SortableTableModel wraps the actual table model, whenever you want to change the data that is displayed, you
should always go to the actual table model and change it. Please make sure you fire the right table model event so
that the SortableTableModel is aware of any change and handles it correctly. This is especially important if you are
not using DefaultTableModel but using AbstractTableModel or TableModel interface directly, where you are responsible
in firing the table model events.
Please note, SortableTable and all other JIDE tables that extend ContextSensitiveTable
uses a JComboBox for
boolean data type, which is different from JTable which uses JCheckBox. This can be solved by returning an
EditorContext in ContextSensitiveTableModel. Please refer to the javadoc of BooleanCheckBoxCellRenderer
for
more information.
- See Also:
- Serialized Form
Fields inherited from class com.jidesoft.grid.JideTable |
_batchProcessing, _cellChangeEvent, _clickCountToStart, _columnAutoResizer, _columnResizer, _headerDraggingMouseMotionListener, _rolloverCellEditor, _rolloverCellEditorListener, _rolloverColumn, _rolloverEditorComp, _rolloverEditorRemover, _rolloverRow, _rowHeights, _rowResizer, ACTION_NAME_CANCEL_EDITING, AUTO_RESIZE_ALL_COLUMNS_FILL, AUTO_RESIZE_FILL, AUTO_RESIZE_LAST_COLUMN_FILL, AUTO_RESIZE_NEXT_COLUMN_FILL, AUTO_RESIZE_SUBSEQUENT_COLUMNS_FILL, CLIENT_PROPERTY_LAZY_CALCULATE_ROW_HEIGHT, EDITOR_AUTO_COMPLETION_MODE_COLUMN, EDITOR_AUTO_COMPLETION_MODE_NONE, EDITOR_AUTO_COMPLETION_MODE_ROW, EDITOR_AUTO_COMPLETION_MODE_TABLE, PROPERTY_CLEAR_SELECTION_ON_TABLE_DATA_CHANGES, PROPERTY_EDITOR_AUTO_COMPLETION_MODE, PROPERTY_FILLS_BOTTOM, PROPERTY_FILLS_GRIDS, PROPERTY_FILLS_RIGHT, PROPERTY_LOAD_SELECTION_ON_TABLE_DATA_CHANGES, PROPERTY_NON_CONTIGUOUS_CELL_SELECTION, PROPERTY_ROW_AUTO_RESIZES, PROPERTY_SCROLL_ROW_WHEN_ROW_HEIGHT_CHANGES, PROPERTY_TABLE_SELECTION_MODEL, ROW_AUTO_RESIZES_PROPERTY |
Fields inherited from class javax.swing.JTable |
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader |
Method Summary |
protected JTableHeader |
createDefaultTableHeader()
Creates the table header. |
protected SortableTableHeaderMouseListener |
createSortableTableHeaderMouseListener()
Creates a SortableTableHeaderMouseListener instance. |
protected ISortableTableModel |
createSortableTableModel(TableModel model)
Creates a SortableTableModel that wraps around the actual model. |
Icon |
createSortIcon(boolean ascending)
Create the sort arrow icon. |
int |
getActualRowAt(int row)
Gets the actual row. |
SortableTableHeaderMouseListener |
getSortableHeaderMouseListener()
Gets a SortableTableHeaderMouseListener instance. |
protected ISortableTableModel |
getSortableTableModel()
Gets any table model which is sortable table model. |
Color |
getSortArrowForeground()
Gets the sort arrow color. |
int |
getSortedRowAt(int actualRow)
Gets the row number after sorting. |
Color |
getSortOrderForeground()
Gets the sort order number foreground color. |
boolean |
isAutoResort()
Checks if the table is automatically resort when data changes. |
boolean |
isEnsureSelectedRowVisibleOnTogglingSort()
Gets the flag indicating if JScrollPane should scroll to make the selected rows visible while clicking the table
header to sort. |
boolean |
isMultiColumnSortable()
Does this table allow sort by multiple columns. |
boolean |
isOptimized()
Checks if the optimized flag is true. |
boolean |
isPreserveSelectionsAfterSorting()
Deprecated. this flag will not take effect, since we will preserve selection anyway after sorting right now. |
protected boolean |
isReusable(ISortableTableModel existingSortableTableModel,
TableModel newModel)
Check if the existing SortableTableModel could be reused when setModel(javax.swing.table.TableModel) is invoked. |
boolean |
isShowSortOrderNumber()
Checks if the table is showing sort order number. |
boolean |
isSortable()
Checks if the table is sortable. |
boolean |
isSortingEnabled()
Checks if user sorting is enabled. |
void |
resort()
Resort the table. |
void |
setAutoResort(boolean autoResort)
AutoResort is a feature that automatically resort the table when table value changes. |
void |
setEnsureSelectedRowVisibleOnTogglingSort(boolean ensureSelectedRowVisibleOnTogglingSort)
Sets the flag indicating if JScrollPane should scroll to make the selected rows visible while clicking the table
header to sort. |
void |
setModel(TableModel model)
|
void |
setMultiColumnSortable(boolean multiColumnSortable)
Set the value if this table allows sort by multiple columns. |
void |
setOptimized(boolean optimized)
If optimized flag is true and the table is already sorted, SortableTableModel will do incremental sorting when
data changes. |
void |
setPreserveSelectionsAfterSorting(boolean preserveSelectionsAfterSorting)
Deprecated. this flag will not take effect, since we will preserve selection anyway after sorting right now. |
void |
setShowSortOrderNumber(boolean showSortOrderNumber)
Sets if the table shows the sort number in table header when there is only column is sorted. |
void |
setSortable(boolean sortable)
Sets if the table is sortable. |
void |
setSortArrowForeground(Color sortArrowForeground)
Sets the sort arrow color. |
void |
setSortingEnabled(boolean sortingEnabled)
Sets sorting enabled or disabled. |
void |
setSortOrderForeground(Color sortOrderForeground)
Sets the sort order number foreground color. |
void |
sortChanged(SortEvent event)
Listens to sortChanged event so that we can repaint the table header in case sort arrow changed. |
void |
sortChanging(SortEvent event)
Listens to sortChanging event. |
void |
sortColumn(int columnIndex)
Sort column specified by columnIndex. |
void |
sortColumn(int columnIndex,
boolean reset)
Sort column specified by columnIndex. |
void |
sortColumn(int columnIndex,
boolean reset,
boolean ascending)
Sort column specified by columnIndex. |
void |
sortColumn(String columnName)
Sort column specified by columnName. |
void |
sortColumn(String columnName,
boolean reset)
Sort column specified by columnName. |
void |
sortColumn(String columnName,
boolean reset,
boolean ascending)
Sort column specified by columnName. |
void |
unsort()
Unsorts any sorting columns. |
Methods inherited from class com.jidesoft.grid.CategorizedTable |
getAscendingIcon, getCategoryCollapsedIcon, getCategoryExpandedIcon, getCollapsedIcon, getCollapsedIcon, getDescendingIcon, getDisabledBackground, getDisabledForeground, getExpandedIcon, getExpandedIcon, getMarginBackground, isExpandIconVisible, isPaintMarginBackground, isUseLnfDefaultSortIcon, isUseTableRendererForCategoryRow, setAscendingIcon, setCategoryCollapsedIcon, setCategoryExpandedIcon, setCollapsedIcon, setDescendingIcon, setDisabledBackground, setDisabledForeground, setExpandedIcon, setExpandIconVisible, setMarginBackground, setPaintMarginBackground, setUseLnfDefaultSortIcon, setUseTableRendererForCategoryRow, updateUI |
Methods inherited from class com.jidesoft.grid.CellSpanTable |
binarySearch, calculateRowHeight, calculateRowHeight, calculateRowHeights, columnAdded, columnAtPoint, columnMoved, columnRemoved, convertModelCellSpanToView, convertViewCellSpanToModel, createCellSpanCache, createDelegateAction, editCellAt, getActualRowHeight, getActualUIClassID, getAutoCellMerge, getCache, getCacheEmpty, getCellEditor, getCellRect, getCellRenderer, getCellSpanAt, getCellSpanAt, getCellSpanFromAutoCellMerge, getCellSpanFromSpanModel, getDirtyRegion, getScrollableUnitIncrement, getSpanModel, getValueAt, invalidateCellSpanCache, isAutoConvertCellSpan, isCellFocused, isCellSelected, isCellSpanCacheEnabled, isCellSpanOn, isKeepColumnAtPoint, isKeepRowAtPoint, isPaintCellSpanAsSelected, muteDefaultKeyStroke, originalColumnAtPoint, originalGetCellRect, originalRowAtPoint, prepareEditor, replaceAction, replaceAction, restoreAction, restoreAction, rolloverCellAt, rowAtPoint, setAutoCellMerge, setAutoConvertCellSpan, setCellSpanCacheEnabled, setKeepColumnAtPoint, setKeepRowAtPoint, setPaintCellSpanAsSelected, shouldCellBePaintedAsFocused, shouldCellBePaintedAsSelected, tableChanged, valueChanged, verifyCellSpan, verifyCellSpan |
Methods inherited from class com.jidesoft.grid.CellStyleTable |
addCellStyleCustomizer, clearCellStyleCustomizers, collectCellStyles, configureEditorComponent, configureRendererComponent, customizeEditorComponent, customizeRendererComponent, getCellStyleAt, getCellStyleCustomizers, getCellStyleProvider, getCellStyles, getFocusCellStyle, getNextStyleModel, getStyleModel, getTableStyleProvider, isFillsSelection, isFillsViewportWithStripe, mergeCellStyle, mergeCellStyles, needPaintStripedBackground, paintCellOverlay, paintCellUnderlay, paintComponent, prepareRenderer, releaseRendererComponent, removeCellStyleCustomizer, setCellStyleProvider, setFillsSelection, setFillsViewportWithStripe, setFocusCellStyle, setTableStyleProvider |
Methods inherited from class com.jidesoft.grid.NavigableTable |
changeSelection, findNearestNavigableCellInColumn, findNearestNavigableCellInRow, findNextNavigableCell, findNextNavigableCellInColumn, findNextNavigableCellInRow, findNextNavigableCellVertically, findPreviousNavigableCell, findPreviousNavigableCellInColumn, findPreviousNavigableCellInRow, findPreviousNavigableCellVertically, getNavigableModel, getNextNavigableModel, isCellNavigable, isNavigationKey, processKeyBinding |
Methods inherited from class com.jidesoft.grid.ContextSensitiveTable |
convertElementToString, createDefaultTransferHandler, getCellClassAt, getCellEditorFromManager, getCellRendererFromManager, getConverterContextAt, getDefaultCellRenderer, getEditorContextAt, invalidateCellRendererCache, isCellEditorManagerEnabled, isCellRendererManagerEnabled, setCellEditorManagerEnabled, setCellRendererManagerEnabled, setDefaultCellRenderer |
Methods inherited from class com.jidesoft.grid.JideTable |
addCellEditorListener, addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, addRowValidator, addUndo, addUndoableEditListener, addValidator, adjustSelectionWhenColumnMoved, alwaysCalculateCellRect, calculateAutoResizedRowHeights, calculateAutoResizedRowHeights, clearSelection, clearSelectionPermanently, columnSelectionChanged, configureEnclosingScrollPaneExplicitly, convertRowIndexToModel, convertRowIndexToView, createCellAutoCompletion, createDefaultColumnsFromModel, createDefaultSelectionModel, createDefaultTableSelectionModel, createRowAutoScrollingListener, createRowHeights, createSortHeaderRenderer, editingCanceled, editingStopped, fireEditingCanceled, fireEditingStarted, fireEditingStarting, fireEditingStopped, fireEditingStopping, getCellEditorListeners, getClickCountToStart, getDefaultRenderer, getEditorAutoCompletionMode, getEditorAutoCompletionMode, getEditorCellRect, getGridColor, getGridColorProvider, getRolloverCellEditor, getRolloverColumn, getRolloverRow, getRowHeight, getRowHeights, getRowValidator, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getTableColumnWidthKeeper, getTableHeaderToolTipText, getTableHeaderToolTipText, getTableSelectionModel, getTextComponentForEditorComponent, getToolTipText, getUndoManager, getValidator, getVerticalGridColor, indexChanged, initTable, isAdjustEditorLocationOnModelChanged, isAlwaysRequestFocusForEditor, isAutoResizeFillMode, isAutoSelectTextWhenStartsEditing, isAutoStartCellEditing, isAutoStartCellEditingKey, isBatchProcessing, isCalculateRowHeightsOnWidthChange, isCellContentVisible, isClearPropertyAtStructureChange, isClearSelectionOnTableDataChanges, isColumnAutoResizable, isColumnResizable, isColumnSelected, isEnableIgnored, isFillBottom, isFillGrids, isFillRight, isFillsBottom, isFillsGrids, isFillsGridsBottom, isFillsGridsRight, isFillsRight, isKeepRowHeights, isLoadSelectionOnTableDataChanged, isNestedTableHeader, isNonContiguousCellSelection, isRollover, isRowAutoResizes, isRowHeightChanged, isRowResizable, isRowSelected, isScrollRowWhenRowHeightChanges, isSelectInsertedRows, isTablePrinting, isValidCellEditingKey, isVariousRowHeights, loadTableRowSettings, paintFillHeader, removeCellEditorListener, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRolloverEditor, removeRowSelectionInterval, removeRowValidator, removeUndoableEditListener, removeValidator, resetTransferHandler, saveTableRowSettings, scrollRowToVisible, selectAll, setAdjustEditorLocationOnModelChanged, setAlwaysRequestFocusForEditor, setAutoResizeMode, setAutoSelectTextWhenStartsEditing, setAutoStartCellEditing, setBatchProcessing, setCalculateRowHeightsOnWidthChange, setCellContentVisible, setClearPropertyAtStructureChange, setClearSelectionOnTableDataChanges, setClickCountToStart, setColumnAutoResizable, setColumnResizable, setColumnSelectionAllowed, setColumnSelectionInterval, setEditorAutoCompletionMode, setEnabled, setEnableIgnored, setFillBottom, setFillGrids, setFillRight, setFillsBottom, setFillsGrids, setFillsRight, setGridColorProvider, setKeepRowHeights, setLoadSelectionOnTableDataChanged, setNestedTableHeader, setNonContiguousCellSelection, setPreferredSize, setRowAutoResizes, setRowHeight, setRowHeight, setRowHeights, setRowResizable, setRowSelectionAllowed, setRowSelectionInterval, setScrollRowWhenRowHeightChanges, setSelectInsertedRows, setSortTableHeaderRenderer, setTableColumnWidthKeeper, setTableHeader, setTablePrinting, setTableSelectionModel, setVariousRowHeights, startCellEditing, validate, validateRow |
Methods inherited from class javax.swing.JTable |
columnMarginChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createScrollPaneForTable, doLayout, editCellAt, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, initializeLocalVars, isCellEditable, isEditing, moveColumn, paramString, print, print, print, print, print, resizeAndRepaint, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setCellEditor, setCellSelectionEnabled, setColumnModel, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowMargin, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, unconfigureEnclosingScrollPane |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
SORTABLE_PROPERTY
public static final String SORTABLE_PROPERTY
- Property name for SORTABLE.
- See Also:
- Constant Field Values
PROPERTY_SHOW_SORT_ORDER_NUMBER
public static final String PROPERTY_SHOW_SORT_ORDER_NUMBER
- Property name for showSortOrderNumber.
- See Also:
- Constant Field Values
MULTICOLUMN_SORTABLE_PROPERTY
public static final String MULTICOLUMN_SORTABLE_PROPERTY
- Property name for MULTICOLUMN_SORTABLE.
- See Also:
- Constant Field Values
SortableTable
public SortableTable()
- Create a SortableTable which is not sortable. If you want to make it sortable, call setSortable(true).
SortableTable
public SortableTable(TableModel model)
- Create a SortableTable. You can pass in any table model. If it is not an instance of SortableTableModel, we will
create a SortableTableModel and wrap around it. If it is an instance of SortTableModel, it will be used
directly.
- Parameters:
model
- any table model.
SortableTable
public SortableTable(TableModel dm,
TableColumnModel cm)
SortableTable
public SortableTable(TableModel dm,
TableColumnModel cm,
ListSelectionModel sm)
SortableTable
public SortableTable(int numRows,
int numColumns)
SortableTable
public SortableTable(Vector<?> rowData,
Vector<?> columnNames)
SortableTable
public SortableTable(Object[][] rowData,
Object[] columnNames)
createSortableTableHeaderMouseListener
protected SortableTableHeaderMouseListener createSortableTableHeaderMouseListener()
- Creates a SortableTableHeaderMouseListener instance.
- Returns:
- the SortableTableHeaderMouseListener instance.
getSortableHeaderMouseListener
public SortableTableHeaderMouseListener getSortableHeaderMouseListener()
- Gets a SortableTableHeaderMouseListener instance.
- Returns:
- the SortableTableHeaderMouseListener instance.
- Since:
- 3.1.0
isMultiColumnSortable
public boolean isMultiColumnSortable()
- Does this table allow sort by multiple columns.
- Returns:
- true if this table allows sort by multiple columns
setMultiColumnSortable
public void setMultiColumnSortable(boolean multiColumnSortable)
- Set the value if this table allows sort by multiple columns. Please note, we simply call
SortableTableModel.setMultiColumnSortable(boolean)
in this case. So if you change the model, you need to call it
again to set the value.
- Parameters:
multiColumnSortable
- pass in true if this you want this table allows sort by multiple columns
isSortable
public boolean isSortable()
- Checks if the table is sortable.
- Returns:
- true if the table is sortable.
setSortable
public void setSortable(boolean sortable)
- Sets if the table is sortable. This method will reset table model. If sortable is true, it will set current table
to SortableTableMode. If false, it will use actual table model which is usually not a SortableTableModel.
- Parameters:
sortable
- true or false.
isShowSortOrderNumber
public boolean isShowSortOrderNumber()
- Checks if the table is showing sort order number. If this flag is false, the sort number will only be displayed
when there are multiple columns are sorted. If there is only one column that is sorted, there will be no sort
number.
- Returns:
- true if the table is sortable.
setShowSortOrderNumber
public void setShowSortOrderNumber(boolean showSortOrderNumber)
- Sets if the table shows the sort number in table header when there is only column is sorted.
- Parameters:
showSortOrderNumber
- true or false
createSortableTableModel
protected ISortableTableModel createSortableTableModel(TableModel model)
- Creates a
SortableTableModel
that wraps around the actual model. Subclass can override it to create
your own SortableTableModel
. For example TreeTable overrides it to create a
SortableTreeTableModel
for TreeTableModel
.
- Parameters:
model
- the actual table model.
- Returns:
- a SortableTableModel.
sortChanging
public void sortChanging(SortEvent event)
- Listens to sortChanging event.
- Specified by:
sortChanging
in interface SortListener
- Parameters:
event
- the sort event
sortChanged
public void sortChanged(SortEvent event)
- Listens to sortChanged event so that we can repaint the table header in case sort arrow changed. By default, we
will keep the selection after sorting changed. You can turn it off by setting
setPreserveSelectionsAfterSorting(boolean)
to false. Also by default, we will not scroll the selection visible
because it will cause flickering when the table data is updated too rapidly. However you can override this method
and call TableUtils.ensureRowSelectionVisible(this) to enable auto-scrolling. If user clicks on the table header
to sort the column, we will ensureRowSelectionVisible in the mouse listener so selection will be scrolled
visible.
- Specified by:
sortChanged
in interface SortListener
- Parameters:
event
- the sort event
isReusable
protected boolean isReusable(ISortableTableModel existingSortableTableModel,
TableModel newModel)
- Check if the existing SortableTableModel could be reused when
setModel(javax.swing.table.TableModel)
is invoked.
- Parameters:
existingSortableTableModel
- the existing SortableTableModelnewModel
- the new underlying table model
- Returns:
- true by default.
- Since:
- 3.5.1
setModel
public void setModel(TableModel model)
- Overrides:
setModel
in class JideTable
sortColumn
public void sortColumn(String columnName)
- Sort column specified by columnName.
- Parameters:
columnName
- name of column to be sorted.
sortColumn
public void sortColumn(String columnName,
boolean reset)
- Sort column specified by columnName.
- Parameters:
columnName
- name of column to be sorted.reset
- whether reset the sort order of all other columns.
sortColumn
public void sortColumn(String columnName,
boolean reset,
boolean ascending)
- Sort column specified by columnName.
- Parameters:
columnName
- name of column to be sorted.reset
- whether reset the sort order of all other columns.ascending
- whether the sort order is ascending or descending.
unsort
public void unsort()
- Unsorts any sorting columns.
sortColumn
public void sortColumn(int columnIndex)
- Sort column specified by columnIndex.
- Parameters:
columnIndex
- index of column to be sorted.
sortColumn
public void sortColumn(int columnIndex,
boolean reset)
- Sort column specified by columnIndex.
- Parameters:
columnIndex
- index of column to be sorted.reset
- whether reset the sort order of all other columns.
sortColumn
public void sortColumn(int columnIndex,
boolean reset,
boolean ascending)
- Sort column specified by columnIndex.
- Parameters:
columnIndex
- index of column to be sorted.reset
- whether reset the sort order of all other columns.ascending
- whether the sort order is ascending or descending.
getActualRowAt
public int getActualRowAt(int row)
- Gets the actual row.
Please note, this method will only return the row index on the immediate table model that the SortableTableModel
wraps. If you need the actual row index at the inner most table model in case you have several levels of wrapped
table models, please use
TableModelWrapperUtils.getActualRowAt(javax.swing.table.TableModel, int, Class)
or
TableModelWrapperUtils.getActualRowAt(javax.swing.table.TableModel, int)
method.
- Parameters:
row
- the row on the UI.
- Returns:
- the actual row in the actual model. It will throw IllegalArgumentException if the row is out of range.
getSortedRowAt
public int getSortedRowAt(int actualRow)
- Gets the row number after sorting.
Please note, this method will treat the row index as it is on the immediate table model that the
SortableTableModel wraps. If the actual row index is on the inner most table model in case you have several
levels of wrapped table models, please use
TableModelWrapperUtils.getRowAt(javax.swing.table.TableModel, int)
method.
- Parameters:
actualRow
- the actual row in actual model.
- Returns:
- the row on UI. -1 if cannot find the row.
getSortableTableModel
protected ISortableTableModel getSortableTableModel()
- Gets any table model which is sortable table model.
- Returns:
- sortable table model
isOptimized
public boolean isOptimized()
- Checks if the optimized flag is true.
- Returns:
- the optimized flag.
setOptimized
public void setOptimized(boolean optimized)
- If optimized flag is true and the table is already sorted, SortableTableModel will do incremental sorting when
data changes. If the flag is false, SortableTableModel will sort completely again when data changed. If your
table model does a lot of small updates - such as a cell update, a row update, a row insertion/deletion, you
should set this flag to true. On the other hand, if your table always does big updates such as
adding/deleting/updating many rows and just fire one fire one event after that, it will be better if you set the
flag to false. You can change this flag on fly. So if you know you will do a big update, set it to false. After
the big data change is done, set it back to true. Default is false. It probably should be true by default
but we have to keep it this way for backward compatible reason as initially we don't have such a flag and the
behavior is acting like the flag is false.
- Parameters:
optimized
- true or false.
isAutoResort
public boolean isAutoResort()
- Checks if the table is automatically resort when data changes.
- Returns:
- true if autoResort. Otherwise false.
setAutoResort
public void setAutoResort(boolean autoResort)
- AutoResort is a feature that automatically resort the table when table value changes. This is the default
behavior and useful in most cases. However there are cases when the data changes frequently, resort will make it
very hard for user to read the value. So in these cases, you can set autoResort to false. Then you will need to
provide a button to call
resort()
to resort the table.
Note: this flag is only used when optimized flag is true. If optimized is false, autoResort is always true.
- Parameters:
autoResort
- true or false.
resort
public void resort()
- Resort the table. When autoResort is false, the table will be out of order after data changes. The method will
resort the table while keeping the sorting columns.
createDefaultTableHeader
protected JTableHeader createDefaultTableHeader()
- Description copied from class:
JideTable
- Creates the table header. If the nested table header is allowed, it will return an instance of NestedTableHeader.
Otherwise, it will return the JTableHeader.
- Overrides:
createDefaultTableHeader
in class JideTable
- Returns:
- table header
getSortArrowForeground
public Color getSortArrowForeground()
- Gets the sort arrow color.
- Returns:
- the sort arrow color.
setSortArrowForeground
public void setSortArrowForeground(Color sortArrowForeground)
- Sets the sort arrow color.
- Parameters:
sortArrowForeground
- the sort arrow color
getSortOrderForeground
public Color getSortOrderForeground()
- Gets the sort order number foreground color.
- Returns:
- the sort order number foreground color.
setSortOrderForeground
public void setSortOrderForeground(Color sortOrderForeground)
- Sets the sort order number foreground color.
- Parameters:
sortOrderForeground
- the text color of the sort order number
isSortingEnabled
public boolean isSortingEnabled()
- Checks if user sorting is enabled.
- Returns:
- true or false.
setSortingEnabled
public void setSortingEnabled(boolean sortingEnabled)
- Sets sorting enabled or disabled. If sorting is disabled, user cannot press table column header to sort it.
However you as developer can still call API to sort the tables. By default sorting is enabled.
- Parameters:
sortingEnabled
- true or false.
isPreserveSelectionsAfterSorting
@Deprecated
public boolean isPreserveSelectionsAfterSorting()
- Deprecated. this flag will not take effect, since we will preserve selection anyway after sorting right now.
- Checks if SortableTable will preserve the selections after sort order changes. If true, we will use saveSelection
and loadSelections methods in TableUtils to preserve the selections. If false, the selections will be gone after
sort. We give this option in case you have your own way to preserve the selections.
- Returns:
- true or false. Default is true.
setPreserveSelectionsAfterSorting
@Deprecated
public void setPreserveSelectionsAfterSorting(boolean preserveSelectionsAfterSorting)
- Deprecated. this flag will not take effect, since we will preserve selection anyway after sorting right now.
- Sets the flag of preserveSelectionsAfterSorting. If true, we will use saveSelection and loadSelections methods in
TableUtils to preserve the selections. If false, the selections will be gone after sorting. We give this option
in case you have your own way to preserve the selections.
- Parameters:
preserveSelectionsAfterSorting
- true or false.
createSortIcon
public Icon createSortIcon(boolean ascending)
- Create the sort arrow icon. Subclass can override it to create your own sort arrow. Although the name is
createSortIcon, you could cache the icon internally and don't create it every time when this method is called.
- Parameters:
ascending
- true or false. True is ascending.
- Returns:
- the sort arrow icon.
isEnsureSelectedRowVisibleOnTogglingSort
public boolean isEnsureSelectedRowVisibleOnTogglingSort()
- Gets the flag indicating if JScrollPane should scroll to make the selected rows visible while clicking the table
header to sort.
- Returns:
- true if should scroll on toggling sort. Otherwise false.
- See Also:
setEnsureSelectedRowVisibleOnTogglingSort(boolean)
setEnsureSelectedRowVisibleOnTogglingSort
public void setEnsureSelectedRowVisibleOnTogglingSort(boolean ensureSelectedRowVisibleOnTogglingSort)
- Sets the flag indicating if JScrollPane should scroll to make the selected rows visible while clicking the table
header to sort.
The default value is true to keep previous behavior.
- Parameters:
ensureSelectedRowVisibleOnTogglingSort
- the flag