public class Table extends Container
The Table class represents a grid of data that can be used for rendering a grid
of components/labels. The table reflects and updates the underlying model data.
Table relies heavily on the TableLayout class and
TableModel interface to present its UI. Unlike a
List a Table doesn't feature a separate renderer
and instead allows developers to derive the class.

| Modifier and Type | Field and Description |
|---|---|
static int |
INNER_BORDERS_ALL
Constant denoting that inner borders should be drawn fully
|
static int |
INNER_BORDERS_COLS
Constant denoting that only inner borders columns should be drawn
|
static int |
INNER_BORDERS_NONE
Constant denoting that inner borders should not be drawn at all
|
static int |
INNER_BORDERS_ROWS
Constant denoting that only inner borders rows should be drawn
|
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR| Constructor and Description |
|---|
Table()
Constructor for usage by GUI builder and automated tools, normally one
should use the version that accepts the model
|
Table(TableModel model)
Create a table with a new model
|
Table(TableModel model,
boolean includeHeader)
Create a table with a new model
|
| Modifier and Type | Method and Description |
|---|---|
protected Component |
createCell(Object value,
int row,
int column,
boolean editable)
Creates a cell based on the given value
|
protected TableLayout.Constraint |
createCellConstraint(Object value,
int row,
int column)
Creates the table cell constraint for the given cell, this method can be overriden for
the purposes of modifying the table constraints.
|
protected Comparator |
createColumnSortComparator(int column)
Returns a generic comparator that tries to work in a way that will sort columns with similar object types.
|
void |
deinitialize()
Invoked to indicate that the component initialization is being reversed
since the component was detached from the container hierarchy.
|
int |
getCellAlignment()
Indicates the alignment of the cells see label alignment for details
|
int |
getCellColumn(Component cell)
Returns the column in which the given cell is placed
|
int |
getCellRow(Component cell)
Returns the row in which the given cell is placed
|
int |
getInnerBorderMode()
Returns the current inner border mode
|
TableModel |
getModel()
Returns the model instance
|
String[] |
getPropertyNames()
A component may expose mutable property names for a UI designer to manipulate, this
API is designed for usage internally by the GUI builder code
|
String[] |
getPropertyTypeNames()
This method is here to workaround an XMLVM array type bug where property types aren't
identified properly, it returns the names of the types using the following type names:
String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer
|
Class[] |
getPropertyTypes()
Matches the property names method (see that method for further details).
|
Object |
getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder
|
int |
getSelectedColumn()
Returns the selected column in the table
|
int |
getSelectedRow()
Returns the selected row in the table
|
int |
getTitleAlignment()
Indicates the alignment of the title see label alignment for details
|
protected boolean |
includeNullValues()
By default createCell/constraint won't be invoked for null values by overriding this method to return true
you can replace this behavior
|
void |
initComponent()
Allows subclasses to bind functionality that relies on fully initialized and
"ready for action" component state
|
boolean |
isDrawBorder()
Indicates whether the table border should be drawn
|
boolean |
isIncludeHeader()
Indicates whether the table should render a table header as the first row
|
boolean |
isSortSupported()
Sort support can be toggled with this flag
|
protected void |
paintGlass(Graphics g)
This method can be overriden by a component to draw on top of itself or its children
after the component or the children finished drawing in a similar way to the glass
pane but more refined per component
|
void |
setBorderSpacing(int horizontal,
int vertical)
Sets the spacing of cells border (relevant only for separate borders and not for collapsed)
|
void |
setCellAlignment(int cellAlignment)
Indicates the alignment of the cells see label alignment for details
|
void |
setCollapseBorder(boolean collapseBorder)
Indicates whether the borders of the cells should collapse to form a one line border
|
void |
setDrawBorder(boolean drawBorder)
Indicates whether the table border should be drawn
|
void |
setDrawEmptyCellsBorder(boolean drawEmptyCellsBorder)
Indicates whether empty cells should have borders (relevant only for separate borders and not for collapsed)
|
void |
setIncludeHeader(boolean includeHeader)
Indicates whether the table should render a table header as the first row
|
void |
setInnerBorderMode(int innerBorder)
Sets how to draw the inner border (All of it, only rows/columns, none, groups)
Note that setting to any mode other than NONE/ALL will result in the border drawing as collapsed whether this is a collpased border or not
|
void |
setModel(TableModel model)
Replaces the underlying model
|
String |
setPropertyValue(String name,
Object value)
Sets a new value to the given property, returns an error message if failed
and null if successful.
|
void |
setSortSupported(boolean sortSupported)
Sort support can be toggled with this flag
|
void |
setTitleAlignment(int titleAlignment)
Indicates the alignment of the title see label alignment for details
|
protected boolean |
shouldDrawInnerBorderAfterRow(int row)
Returns whether an inner border should be drawn after the specified row.
|
void |
sort(int column,
boolean ascending)
Sorts the given column programmatically
|
int |
translateSortedRowToModelRow(int row)
If the table is sorted returns the position of the row in the actual
underlying model
|
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintBackground, paintBorderBackground, paintComponentBackground, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesaddDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainspublic static final int INNER_BORDERS_NONE
public static final int INNER_BORDERS_ROWS
public static final int INNER_BORDERS_COLS
public static final int INNER_BORDERS_ALL
public Table()
public Table(TableModel model)
model - the model underlying this tablepublic Table(TableModel model, boolean includeHeader)
model - the model underlying this tableincludeHeader - Indicates whether the table should render a table header as the first rowpublic int getSelectedRow()
protected boolean includeNullValues()
public int getSelectedColumn()
protected void paintGlass(Graphics g)
paintGlass in class Containerg - the graphics contextprotected Comparator createColumnSortComparator(int column)
column - the column that's sortedpublic void sort(int column,
boolean ascending)
column - the column to sortascending - true to sort in ascending orderprotected Component createCell(Object value, int row, int column, boolean editable)
value - the new value objectrow - row number, -1 for the header rowscolumn - column numbereditable - true if the cell is editablepublic void initComponent()
initComponent in class Componentpublic void deinitialize()
deinitialize in class Componentpublic void setModel(TableModel model)
model - the new modelpublic TableModel getModel()
public boolean isDrawBorder()
public void setDrawBorder(boolean drawBorder)
drawBorder - the drawBorder to setpublic void setInnerBorderMode(int innerBorder)
innerBorder - one of the INNER_BORDER_* constantspublic int getInnerBorderMode()
protected boolean shouldDrawInnerBorderAfterRow(int row)
row - The row in questionpublic void setCollapseBorder(boolean collapseBorder)
collapseBorder - true to collapse (default), false for separate borderspublic void setDrawEmptyCellsBorder(boolean drawEmptyCellsBorder)
drawEmptyCellsBorder - - true to draw (default), false otherwisepublic void setBorderSpacing(int horizontal,
int vertical)
horizontal - - The horizontal spacingvertical - - The vertical spacingpublic int getTitleAlignment()
Label.setAlignment(int)public void setTitleAlignment(int titleAlignment)
titleAlignment - the title alignmentLabel.setAlignment(int)public int getCellColumn(Component cell)
cell - the component representing the cell placed in the tablepublic int getCellRow(Component cell)
cell - the component representing the cell placed in the tablepublic int getCellAlignment()
Label.setAlignment(int)public void setCellAlignment(int cellAlignment)
cellAlignment - the table cell alignmentLabel.setAlignment(int)public boolean isIncludeHeader()
public void setIncludeHeader(boolean includeHeader)
includeHeader - the includeHeader to setprotected TableLayout.Constraint createCellConstraint(Object value, int row, int column)
value - the value of the cellrow - the table rowcolumn - the table columnpublic String[] getPropertyNames()
getPropertyNames in class Componentpublic Class[] getPropertyTypes()
getPropertyTypes in class Componentpublic String[] getPropertyTypeNames()
getPropertyTypeNames in class Componentpublic Object getPropertyValue(String name)
getPropertyValue in class Componentname - the name of the propertypublic String setPropertyValue(String name, Object value)
setPropertyValue in class Componentname - the name of the propertyvalue - new value for the propertypublic int translateSortedRowToModelRow(int row)
row - the row as it visually appears in the table or in the
createCell methodpublic boolean isSortSupported()
public void setSortSupported(boolean sortSupported)
sortSupported - the sortSupported to set