Class GTable
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,CellEditorListener
,ListSelectionListener
,RowSorterListener
,TableColumnModelListener
,TableModelListener
,Scrollable
- Direct Known Subclasses:
FVTable
,GhidraTable
JTable
that provides navigation and auto-lookup.
By default, both of these features are disabled.
Auto-lookup is only supported on one column and must be specified
using the setAutoLookupColumn()
method.
Auto-lookup allows a user to begin typing the first few letters of a desired row. The table will attempt to locate the first row that contains the letters typed up to that point. There is an 800ms timeout between typed letters, at which point the list of typed letters will be flushed.
Auto-lookup is much faster if the underlying table model implements
SortedTableModel
, because a binary search can used
to locate the desired row. A linear search is used if the model is not sorted.
Other features provided:
- Column hiding/showing
- Multi-column sorting
- Column settings
- Column state saving (visibility, size, positioning, sort values)
- Selection management (saving/restoring selection when used with a filter panel)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
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
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorDescriptionGTable()
Constructs a new GTableGTable
(TableModel dm) Constructs a new GTable using the specified table model. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if key strokes are used to trigger actions.void
void
protected AutoLookup
Allows subclasses to change the type ofAutoLookup
created by this tableprotected TableColumnModel
void
protected <T> SelectionManager
static void
createSharedActions
(Tool tool, ToolActions toolActions, String owner) void
dispose()
Call this when the table will no longer be usedboolean
editCellAt
(int row, int column, EventObject e) If you just begin typing into an editable cell in a JTable, then the cell editor will be displayed.protected AutoLookup
getCellRenderer
(int row, int col) final TableCellRenderer
getCellRendererOverride
(int row, int col) Performs custom work to locate renderers for special table model types.Returns the underlying ConfigurableColumnTableModel if one is in-usegetDefaultRenderer
(Class<?> columnClass) final TableCellRenderer
getHeaderRendererOverride
(int col) Performs custom work to locate header renderers for special table model types.Returns theSelectionManager
in use by this GTable.getTableColumnPopupMenu
(int columnIndex) protected TableModel
Unrolls the current model by checking if the current model is inside of a wrapper table model.getValueAt
(int row, int column) protected void
Installs the defaultTableCellRenderer
s for known Ghidra table cell data classes.protected void
boolean
void
A method that allows clients to signal to this GTable and its internals that the table model has changed.protected boolean
processKeyBinding
(KeyStroke ks, KeyEvent e, int condition, boolean pressed) void
void
Signals that the preferences of this table (visible columns, sort order, etc.) should be saved.void
void
selectRow
(int row) Selects the given row.boolean
selectRow
(MouseEvent event) Selects the row under the given mouse point.void
setAccessibleNamePrefix
(String namePrefix) Sets an accessible name on the GTable such that screen readers will properly describe them.void
setActionsEnabled
(boolean b) Enables the keyboard actions to pass through this table and up the component hierarchy.void
setAutoEditEnabled
(boolean allowAutoEdit) Enables or disables auto-edit.void
setAutoLookupColumn
(int lookupColumn) Sets the column in which auto-lookup will be enabled.void
setAutoLookupTimeout
(long timeout) Sets the delay between keystrokes after which each keystroke is considered a new lookupvoid
setColumnHeaderPopupEnabled
(boolean enabled) void
setColumnModel
(TableColumnModel columnModel) void
setHTMLRenderingEnabled
(boolean enable) Enables and disables the rendering of HTML content in this table.void
setModel
(TableModel dataModel) void
setPreferenceKey
(String preferenceKey) Sets the key for saving and restoring column configuration state.void
setRowHeight
(int height) void
setSelectionModel
(ListSelectionModel newModel) void
void
setUserSortingEnabled
(boolean enabled) Allows for the disabling of the user's ability to sort an instance ofAbstractSortedTableModel
by clicking the table's headers.void
setVisibleRowCount
(int visibleRowCount) protected boolean
A method that subclasses can override to signal that they wish not to have this table's built-in popup actions.void
protected TableCellRenderer
wrapDefaultTableCellRenderer
(TableCellRenderer renderer, Class<?> columnClass) Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAtPoint, columnMarginChanged, columnMoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
GTable
public GTable()Constructs a new GTable -
GTable
Constructs a new GTable using the specified table model.- Parameters:
dm
- the table model
-
-
Method Details
-
setUI
-
setVisibleRowCount
public void setVisibleRowCount(int visibleRowCount) -
getPreferredScrollableViewportSize
- Specified by:
getPreferredScrollableViewportSize
in interfaceScrollable
- Overrides:
getPreferredScrollableViewportSize
in classJTable
-
tableChanged
- Specified by:
tableChanged
in interfaceTableModelListener
- Overrides:
tableChanged
in classJTable
-
selectRow
public void selectRow(int row) Selects the given row. This is a convenience method forJTable.setRowSelectionInterval(int, int)
.- Parameters:
row
- The row to select
-
selectRow
Selects the row under the given mouse point. This method is useful when the user triggers a popup mouse action and you would like to have the table select that row if it is not already selected. This allows you to guarantee that there is always a selection when the user triggers a popup menu.- Parameters:
event
- The event that triggered the popup menu- Returns:
- true if the row is selected or was already selected.
-
createDefaultColumnModel
- Overrides:
createDefaultColumnModel
in classJTable
-
createAutoLookup
Allows subclasses to change the type ofAutoLookup
created by this table- Returns:
- the auto lookup
-
setColumnModel
- Overrides:
setColumnModel
in classJTable
-
setSelectionModel
- Overrides:
setSelectionModel
in classJTable
-
setModel
-
createSelectionManager
-
getSelectionManager
Returns theSelectionManager
in use by this GTable.null
is returned if the user has installed their ownListSelectionModel
.- Returns:
- the selection manager
-
notifyTableChanged
A method that allows clients to signal to this GTable and its internals that the table model has changed. Usually,tableChanged(TableModelEvent)
is called, but clients alter the table, but do not do so through the model. In this case, they need a way to signal to the table that the model has been updated.- Parameters:
event
- the event for the change
-
dispose
public void dispose()Call this when the table will no longer be used -
setAutoLookupTimeout
public void setAutoLookupTimeout(long timeout) Sets the delay between keystrokes after which each keystroke is considered a new lookup- Parameters:
timeout
- the timeout- See Also:
-
getAutoLookup
-
setAutoLookupColumn
public void setAutoLookupColumn(int lookupColumn) Sets the column in which auto-lookup will be enabled.Note: calling this method with a valid column index will disable key binding support of actions. See
setActionsEnabled(boolean)
. Passing an invalid column index will disable the auto-lookup feature.- Parameters:
lookupColumn
- the column in which auto-lookup will be enabled
-
setActionsEnabled
public void setActionsEnabled(boolean b) Enables the keyboard actions to pass through this table and up the component hierarchy. Specifically, passing true to this method allows unmodified keystrokes to work in the tool when this table is focused. Modified keystrokes, likeCtrl-C
, will work at all times. Finally, if true is passed to this method, then theauto lookup
feature is disabled.The default state is for actions to be disabled.
- Parameters:
b
- true allows keyboard actions to pass up the component hierarchy.
-
areActionsEnabled
public boolean areActionsEnabled()Returns true if key strokes are used to trigger actions.This method has a relationship with
setAutoLookupColumn(int)
. If this method returnstrue
, then the auto-lookup feature is disabled. If this method returnsfalse
, then the auto-lookup may or may not be enabled.- Returns:
- true if key strokes are used to trigger actions
- See Also:
-
setAccessibleNamePrefix
Sets an accessible name on the GTable such that screen readers will properly describe them.This prefix should be the base name that describes the type of items in the table. This method will then append the necessary information to property name the table.
- Parameters:
namePrefix
- the accessible name prefix to assign to the filter component. For example if the table contains fruits, then "Fruits" would be an appropriate prefix name.
-
setAutoEditEnabled
public void setAutoEditEnabled(boolean allowAutoEdit) Enables or disables auto-edit. When enabled, the user can start typing to trigger an edit of an editable table cell.- Parameters:
allowAutoEdit
- true for auto-editing
-
installEditKeyBinding
protected void installEditKeyBinding() -
setRowHeight
public void setRowHeight(int height) - Overrides:
setRowHeight
in classJTable
-
columnAdded
- Specified by:
columnAdded
in interfaceTableColumnModelListener
- Overrides:
columnAdded
in classJTable
-
columnRemoved
- Specified by:
columnRemoved
in interfaceTableColumnModelListener
- Overrides:
columnRemoved
in classJTable
-
getConfigurableColumnTableModel
Returns the underlying ConfigurableColumnTableModel if one is in-use- Returns:
- the underlying ConfigurableColumnTableModel if one is in-use
-
getUnwrappedTableModel
Unrolls the current model by checking if the current model is inside of a wrapper table model.- Returns:
- this class's table model, unwrapped as needed
-
processKeyBinding
- Overrides:
processKeyBinding
in classJTable
-
getDefaultRenderer
- Overrides:
getDefaultRenderer
in classJTable
-
wrapDefaultTableCellRenderer
protected TableCellRenderer wrapDefaultTableCellRenderer(TableCellRenderer renderer, Class<?> columnClass) -
initDefaultRenderers
protected void initDefaultRenderers()Installs the defaultTableCellRenderer
s for known Ghidra table cell data classes. Subclasses can override this method to add additional types or to change the default associations. -
createDefaultColumnsFromModel
public void createDefaultColumnsFromModel()- Overrides:
createDefaultColumnsFromModel
in classJTable
-
getToolTipText
- Overrides:
getToolTipText
in classJTable
-
setHTMLRenderingEnabled
public void setHTMLRenderingEnabled(boolean enable) Enables and disables the rendering of HTML content in this table. If enabled, this table will:- Wrap tooltip text content with an <html> tag so that it is possible for the content to be formatted in a manner that is easier for the user read, and
- Enable any
default
GTableCellRenderer
instances to render HTML content, which they do not do by default.
HTML rendering is disabled by default.
- Parameters:
enable
- true to enable HTML rendering; false to disable it
-
setPreferenceKey
Sets the key for saving and restoring column configuration state. Use this if you have multiple instances of a table and you want different column settings for each instance.- Parameters:
preferenceKey
- the unique string to use a key for this instance.
-
getPreferenceKey
- Returns:
- the preference key
- See Also:
-
savePreferences
public void savePreferences()Signals that the preferences of this table (visible columns, sort order, etc.) should be saved. Most clients never need to call this method, as changes are saved for free when the user manipulates columns. However, sometimes the client can change the state of the columns programmatically, which is not guaranteed to get saved; for example, setting the sort state of a sorted table model programmatically will not get saved. -
setUserSortingEnabled
public void setUserSortingEnabled(boolean enabled) Allows for the disabling of the user's ability to sort an instance ofAbstractSortedTableModel
by clicking the table's headers. The default setting is enabled.- Parameters:
enabled
- true to enable; false to disable
-
setColumnHeaderPopupEnabled
public void setColumnHeaderPopupEnabled(boolean enabled) -
isColumnHeaderPopupEnabled
public boolean isColumnHeaderPopupEnabled() -
getTableColumnPopupMenu
-
getCellRenderer
- Overrides:
getCellRenderer
in classJTable
-
getCellRendererOverride
Performs custom work to locate renderers for special table model types. This method allows clients to bypass thegetCellRenderer(int, int)
, which is sometimes overridden by subclasses to return a hard-coded renderer. In that case, some clients still want a way to perform normal cell renderer lookup.- Parameters:
row
- the rowcol
- the column- Returns:
- the cell renderer
-
getHeaderRendererOverride
Performs custom work to locate header renderers for special table model types. The headers are located and installed at the time the table's model is set.- Parameters:
col
- the column- Returns:
- the header cell renderer
-
editCellAt
If you just begin typing into an editable cell in a JTable, then the cell editor will be displayed. However, the editor component will not have a focus. This method has been overridden to request focus on the editor component.- Overrides:
editCellAt
in classJTable
- See Also:
-
requestTableEditorFocus
public void requestTableEditorFocus() -
scrollToSelectedRow
public void scrollToSelectedRow() -
getValueAt
- Overrides:
getValueAt
in classJTable
-
supportsPopupActions
protected boolean supportsPopupActions()A method that subclasses can override to signal that they wish not to have this table's built-in popup actions. Subclasses will almost never need to override this method.- Returns:
- true if popup actions are supported
-