Class Table<T extends Table<T>>
- All Implemented Interfaces:
com.oorian.css.TableIntf<T>
<table> element for displaying tabular data.
The Table class provides a Java representation of the HTML table element, which creates structured data tables with rows and cells. It supports complete table structure including header (thead), body (tbody), and footer (tfoot) sections, along with comprehensive CSS table styling capabilities.
Features:
- Structured table sections: header, body, and footer
- Dynamic row and cell management
- Border collapse and spacing control
- Table layout algorithm configuration (auto/fixed)
- Caption positioning control
- Empty cells display handling
- Caption support for table titles
- Column groups for column-level styling
- Sortable table support
- Flexible styling for all table sections
- Programmatic row access and manipulation
Usage Example:
// Create a basic data table
Table table = new Table();
table.setBorderCollapse(BorderCollapse.COLLAPSE);
table.setWidth("100%");
// Add header row
Tr headerRow = table.getHeader().addRow();
headerRow.addHeaderCell("Name");
headerRow.addHeaderCell("Email");
headerRow.addHeaderCell("Role");
// Add data rows
Tr dataRow = table.addRow();
dataRow.addDataCell("John Doe");
dataRow.addDataCell("john@example.com");
dataRow.addDataCell("Administrator");
// Add a caption
table.setCaption("Monthly Sales Report");
// Add column groups
Colgroup colgroup = new Colgroup();
colgroup.addCol(new Col(1));
colgroup.addCol(new Col(2));
table.addColgroup(colgroup);
// Configure table layout
table.setTableLayout(TableLayout.FIXED);
table.setBorderSpacing(5);
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddColgroup(Colgroup colgroup) Adds a column group to this table.addElement(Element child) Adds a child element to this table.addRow()Creates and adds a new row to the table body.voidAdds an existing row to the table body.getBody()Returns the table body (tbody) section.Returns the table caption, ornullif no caption has been set.Returns the table footer (tfoot) section.Returns the table header (thead) section.getRow(int index) Returns the row at the specified index in the table body.voidRemoves all rows from the table body.voidremoveRow(int index) Removes a row from the table body at the specified index.voidremoveRows(int start, int end) Removes a range of rows from the table body.voidsetBorder(boolean flag) Sets whether the table displays a border.setBorderCollapse(BorderCollapse attrValue) Sets the border-collapse property using an enum value.final TsetBorderCollapse(String borderCollapse) Sets the border-collapse property using a string value.final TsetBorderSpacing(int pixels) Sets the border-spacing property using a pixel value.setBorderSpacing(int hspacing, int vspacing) Sets the border-spacing property with separate horizontal and vertical pixel values.setBorderSpacing(Units units) Sets the border-spacing property using a Units object.setBorderSpacing(Units hspacing, Units vspacing) Sets the border-spacing property with separate horizontal and vertical Units values.final TsetBorderSpacing(String spacing) Sets the border-spacing property using a string value.setBorderSpacing(String hspacing, String vspacing) Sets the border-spacing property with separate horizontal and vertical string values.voidsetCaption(Caption caption) Sets the table caption, replacing any existing caption.voidsetCaption(String text) Sets the table caption with the specified text, replacing any existing caption.setCaptionSide(CaptionSide attrValue) Sets the caption-side property using an enum value.final TsetCaptionSide(String attrValue) Sets the caption-side property using a string value.setEmptyCells(EmptyCells attrValue) Sets the empty-cells property using an enum value.final TsetEmptyCells(String attrValue) Sets the empty-cells property using a string value.voidsetFooterStyle(CssStyle style) Sets the style for the table footer section using a CssStyle object.voidsetFooterStyle(String cssClass) Sets the CSS class for the table footer section.voidsetHeaderStyle(CssStyle style) Sets the style for the table header section using a CssStyle object.voidsetHeaderStyle(String cssClass) Sets the CSS class for the table header section.voidsetSortable(boolean sortable) Sets whether the table is sortable by clicking on column headers.final TsetTableLayout(TableLayout attrValue) Sets the table-layout property using an enum value.final TsetTableLayout(String attrValue) Sets the table-layout property using a string value.Methods inherited from class com.oorian.html.StyledElement
addClass, addStyle, addStyle, addStyleAttribute, addTransition, animate, clearTransitions, getActiveStyle, getCssClass, getDisabledStyle, getFocusStyle, getFocusVisibleStyle, getHoverStyle, getHtml, getStyle, getStyleAttribute, hidden, hide, initialize, isDisplayed, isTransitionForwardActive, onHide, onRemovedFromPage, onShow, removeClass, setActiveStyle, setAlignContent, setAlignContent, setAlignItems, setAlignItems, setAlignSelf, setAlignSelf, setAnimation, setAnimationDelay, setAnimationDelay, setAnimationDelay, setAnimationDirection, setAnimationDirection, setAnimationDuration, setAnimationDuration, setAnimationDuration, setAnimationFillMode, setAnimationFillMode, setAnimationIterationCount, setAnimationIterationCount, setAnimationIterationCount, setAnimationName, setAnimationPlayState, setAnimationPlayState, setAnimationTimingFunction, setAnimationTimingFunction, setAnimationTimingFunction, setAnimationTimingFunction, setBackdropFilter, setBackdropFilter, setBackfaceVisibility, setBackfaceVisibility, setBackground, setBackground, setBackgroundAttachment, setBackgroundAttachment, setBackgroundBlendMode, setBackgroundBlendMode, setBackgroundClip, setBackgroundClip, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundImage, setBackgroundImage, setBackgroundOrigin, setBackgroundOrigin, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundPosition, setBackgroundRepeat, setBackgroundRepeat, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBackgroundSize, setBlur, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorder, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottom, setBorderBottomColor, setBorderBottomColor, setBorderBottomLeftRadius, setBorderBottomLeftRadius, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderBottomRightRadius, setBorderBottomRightRadius, setBorderBottomStyle, setBorderBottomStyle, setBorderBottomWidth, setBorderBottomWidth, setBorderBottomWidth, setBorderBottomWidth, setBorderColor, setBorderColor, setBorderColor, setBorderColor, setBorderImage, setBorderImage, setBorderImageOutset, setBorderImageRepeat, setBorderImageSlice, setBorderImageSource, setBorderImageWidth, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeft, setBorderLeftColor, setBorderLeftColor, setBorderLeftStyle, setBorderLeftStyle, setBorderLeftWidth, setBorderLeftWidth, setBorderLeftWidth, setBorderLeftWidth, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRadius, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRight, setBorderRightColor, setBorderRightColor, setBorderRightStyle, setBorderRightStyle, setBorderRightWidth, setBorderRightWidth, setBorderRightWidth, setBorderRightWidth, setBorderStyle, setBorderStyle, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTop, setBorderTopColor, setBorderTopColor, setBorderTopLeftRadius, setBorderTopLeftRadius, setBorderTopLeftRadius, setBorderTopRightRadius, setBorderTopRightRadius, setBorderTopRightRadius, setBorderTopStyle, setBorderTopStyle, setBorderTopWidth, setBorderTopWidth, setBorderTopWidth, setBorderTopWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBorderWidth, setBottom, setBottom, setBottom, setBoxShadow, setBoxShadow, setBoxShadow, setBoxShadow, setBoxShadow, setBoxSizing, setBoxSizing, setBreakAfter, setBreakBefore, setBreakInside, setBrightness, setClass, setClear, setClear, setClip, setClipPath, setClipPath, setColGap, setColGap, setColor, setColor, setColumnCount, setColumnCount, setColumnFill, setColumnFill, setColumnGap, setColumnRule, setColumnRuleColor, setColumnRuleColor, setColumnRuleStyle, setColumnRuleStyle, setColumnRuleWidth, setColumnRuleWidth, setColumns, setColumns, setColumns, setColumnSpan, setColumnWidth, setColumnWidth, setColumnWidth, setContrast, setCounterIncrement, setCounterReset, setCursor, setCursor, setDirection, setDirection, setDisabledStyle, setDisplay, setDisplay, setFilter, setFilter, setFilterOpacity, setFlex, setFlexBasis, setFlexDirection, setFlexDirection, setFlexFlow, setFlexGrow, setFlexGrow, setFlexShrink, setFlexShrink, setFlexWrap, setFlexWrap, setFloat, setFloat, setFocusStyle, setFocusVisibleStyle, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFont, setFontFace, setFontFamily, setFontFamily, setFontFeatureSettings, setFontKerning, setFontLanguageOverride, setFontSize, setFontSize, setFontSize, setFontSizeAdjust, setFontStretch, setFontStretch, setFontStyle, setFontStyle, setFontSynthesis, setFontVariant, setFontVariant, setFontVariantAlternates, setFontVariantCaps, setFontVariantEastAsian, setFontVariantLigatures, setFontVariantNumeric, setFontVariantPosition, setFontWeight, setFontWeight, setGap, setGap, setGap, setGap, setGrayscale, setHangingPunctuation, setHangingPunctuation, setHeight, setHeight, setHeight, setHoverStyle, setHueRotate, setHyphens, setImageOrientation, setImageRendering, setImageResolution, setImeMode, setInvert, setJustifyContent, setJustifyContent, setKeyFrames, setLeft, setLeft, setLeft, setLetterSpacing, setLetterSpacing, setLetterSpacing, setLetterSpacing, setLineBreak, setLineHeight, setLineHeight, setLineHeight, setLineHeight, setMargin, setMargin, setMargin, setMargin, setMargin, setMarginBottom, setMarginBottom, setMarginBottom, setMarginLeft, setMarginLeft, setMarginLeft, setMarginRight, setMarginRight, setMarginRight, setMarginTop, setMarginTop, setMarginTop, setMark, setMarkAfter, setMarkBefore, setMarks, setMarqueeDirection, setMarqueePlayCount, setMarqueeSpeed, setMarqueeStyle, setMask, setMaskType, setMaxHeight, setMaxHeight, setMaxHeight, setMaxHeightToWindowHeight, setMaxWidth, setMaxWidth, setMaxWidth, setMaxWidthToWindowWidth, setMinHeight, setMinHeight, setMinHeight, setMinHeightToWindowHeight, setMinWidth, setMinWidth, setMinWidth, setMinWidthToWindowWidth, setNavDown, setNavIndex, setNavIndex, setNavLeft, setNavRight, setNavUp, setObjectFit, setObjectPosition, setOnClickNavigateBack, setOnClickNavigateBack, setOnClickNavigateBack, setOnClickNavigateForward, setOnClickNavigateForward, setOnClickNavigateForward, setOnClickNavigateTo, setOnDblClick, setOnDblClickChange, setOpacity, setOpacity, setOrder, setOrder, setOrphans, setOutline, setOutline, setOutline, setOutline, setOutlineColor, setOutlineColor, setOutlineOffset, setOutlineOffset, setOutlineOffset, setOutlineStyle, setOutlineStyle, setOutlineWidth, setOutlineWidth, setOutlineWidth, setOutlineWidth, setOverflow, setOverflow, setOverflow, setOverflowWrap, setOverflowX, setOverflowX, setOverflowY, setOverflowY, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPadding, setPaddingBottom, setPaddingBottom, setPaddingBottom, setPaddingLeft, setPaddingLeft, setPaddingLeft, setPaddingRight, setPaddingRight, setPaddingRight, setPaddingTop, setPaddingTop, setPaddingTop, setPageBreakAfter, setPageBreakAfter, setPageBreakBefore, setPageBreakBefore, setPageBreakInside, setPageBreakInside, setPerspective, setPerspective, setPerspective, setPerspectiveOrigin, setPerspectiveOrigin, setPerspectiveOrigin, setPerspectiveOrigin, setPhonemes, setPosition, setPosition, setPosition, setPosition, setPosition, setQuotes, setResize, setResize, setResizeToWindowHeight, setResizeToWindowHeight, setResizeToWindowWidth, setRest, setRestAfter, setRestBefore, setRight, setRight, setRight, setRotate, setRotate, setRowGap, setRowGap, setSaturate, setScale, setScale, setSepia, setShow, setSize, setSize, setSize, setSkewX, setSkewY, setStyle, setStyle, setTabSize, setTabSize, setTabSize, setTabSize, setTextAlign, setTextAlign, setTextAlignLast, setTextAlignLast, setTextCombineUpright, setTextCombineWeight, setTextDecoration, setTextDecoration, setTextDecorationColor, setTextDecorationColor, setTextDecorationLine, setTextDecorationLine, setTextDecorationStyle, setTextDecorationStyle, setTextIndent, setTextIndent, setTextIndent, setTextIndent, setTextJustify, setTextJustify, setTextOrientation, setTextOverflow, setTextOverflow, setTextSelectDisabled, setTextShadow, setTextShadow, setTextShadow, setTextShadow, setTextShadow, setTextTransform, setTextTransform, setTextUnderlinePosition, setTop, setTop, setTop, setTransform, setTransform, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformOrigin, setTransformStyle, setTransformStyle, setTransition, setTransitionDelay, setTransitionDelay, setTransitionDelay, setTransitionDuration, setTransitionDuration, setTransitionDuration, setTransitionProperty, setTransitionTimingFunction, setTransitionTimingFunction, setTransitionTimingFunction, setTransitionTimingFunction, setTranslateX, setTranslateY, setTranslateZ, setUnicodeBidi, setUnicodeBidi, setVerticalAlign, setVerticalAlign, setVisibility, setVisibility, setVoiceBalance, setVoiceDuration, setVoicePitch, setVoicePitchRange, setVoiceRate, setVoiceStress, setVoiceVolume, setWhiteSpace, setWhiteSpace, setWidows, setWidth, setWidth, setWidth, setWordBreak, setWordBreak, setWordSpacing, setWordSpacing, setWordSpacing, setWordSpacing, setWordWrap, setWordWrap, setWritingMode, setZIndex, setZIndex, show, shown, stopAnimation, transitionForward, transitionForward, transitionReverse, transitionReverse, updateStyle, updateStyle, updateStyleIfChangedMethods inherited from class com.oorian.html.VisualElement
clearOnClick, click, disable, enable, getAccessKey, getAutoCapitalize, getEnterKeyHint, getInputMode, getPopover, getRole, getTabIndex, getTitle, isAutoFocus, isContentEditable, isDisabled, isDraggable, isHidden, isInert, isSpellCheck, onDisabled, onEnabled, setAccessKey, setAriaAtomic, setAriaBusy, setAriaChecked, setAriaCheckedMixed, setAriaControls, setAriaCurrent, setAriaDescribedBy, setAriaDisabled, setAriaErrorMessage, setAriaExpanded, setAriaHasPopup, setAriaHasPopup, setAriaHidden, setAriaInvalid, setAriaLabel, setAriaLabelledBy, setAriaLevel, setAriaLive, setAriaModal, setAriaOwns, setAriaPressed, setAriaRequired, setAriaSelected, setAriaValueRange, setAriaValueText, setAutoCapitalize, setAutoFocus, setConsumeEvent, setContentEditable, setDisabled, setDraggable, setDropAllowed, setEnterKeyHint, setFocus, setHidden, setInert, setInputMode, setOnAnimationCancel, setOnAnimationEnd, setOnAnimationIteration, setOnAnimationStart, setOnAuxClick, setOnBeforeInput, setOnBeforeToggle, setOnBlur, setOnChange, setOnClick, setOnClickChange, setOnCompositionEnd, setOnCompositionStart, setOnCompositionUpdate, setOnContextMenu, setOnCopy, setOnCut, setOnDocumentResize, setOnFocus, setOnFocusIn, setOnFocusOut, setOnFormData, setOnGotPointerCapture, setOnInput, setOnInvalid, setOnKeyDown, setOnKeyPressed, setOnKeyUp, setOnLostPointerCapture, setOnMouseDown, setOnMouseEnter, setOnMouseLeave, setOnMouseMove, setOnMouseOut, setOnMouseOutChangeClass, setOnMouseOutChangeStyle, setOnMouseOutChangeStyle, setOnMouseOver, setOnMouseOverChangeClass, setOnMouseOverChangeStyle, setOnMouseOverChangeStyle, setOnMouseOverShow, setOnMouseUp, setOnPageLoad, setOnPaste, setOnPointerCancel, setOnPointerDown, setOnPointerEnter, setOnPointerLeave, setOnPointerMove, setOnPointerOut, setOnPointerOver, setOnPointerUp, setOnResize, setOnScroll, setOnScrollEnd, setOnSelect, setOnSelectionChange, setOnSelectStart, setOnToggle, setOnTouchCancel, setOnTouchEnd, setOnTouchMove, setOnTouchStart, setOnTransitionCancel, setOnTransitionEnd, setOnTransitionRun, setOnTransitionStart, setOnWheel, setOnWindowResize, setPopover, setRole, setRole, setSpellCheck, setTabIndex, setTitle, setTooltipMethods inherited from class com.oorian.html.Element
addAttribute, addAttribute, addAttribute, addAttribute, addLineBreak, addLineOfText, addLineOfText, addLineOfText, addParagraph, addParagraph, addSpacer, addText, addText, addText, addText, assignId, containsElement, containsElement, create, dispatchEvent, dispatchEvent, dispatchEvent, dispatchEvent, equals, excludeId, executeJs, executeJs, executeJs, getAccept, getAllElements, getAncestor, getAttribute, getAttributes, getComponent, getDir, getElement, getElementById, getElementCount, getElementCount, getElements, getElements, getElementsByComponentName, getElementsByTagName, getHtml, getId, getInnerHtml, getInnerHtml, getIs, getItemId, getItemProp, getItemRef, getItemType, getLang, getNextSibling, getPage, getParent, getPart, getPrevSibling, getSlot, getTagName, getTextContent, getUrl, hasAttribute, hasElements, insertElement, isChildOf, isClosedTag, isCreated, isDescendantOf, isDescendantOf, isInitialized, isItemScope, isTranslate, onCallback, onCreated, onElementAdded, onElementRemoved, onHashChange, onHidden, onInitialized, onJsReturn, onPageLoaded, onPageUnloaded, onRefresh, onShown, onUpdated, onUserEvent, prewrite, recreate, refresh, refresh, registerAddition, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerListener, registerSubtraction, registerUpdate, removeAllElements, removeAttribute, removeAttribute, removeElement, removeElement, removeFromParent, requestCallback, requestCallback, requestCallback, requestCallback, resetId, scrollTo, scrollToBottom, scrollToTop, self, sendCommand, sendUpdate, setAccept, setComponent, setDir, setDir, setElement, setId, setIs, setItemId, setItemProp, setItemRef, setItemScope, setItemType, setLang, setOnError, setOnLoad, setPage, setParent, setPart, setSlot, setTagName, setText, setText, setText, setText, setTranslate, toString, unregisterListener, update, updateAttributes
-
Field Details
-
CHAR_SORT
public static final int CHAR_SORT- See Also:
-
NUM_SORT
public static final int NUM_SORT- See Also:
-
DATE_SORT
public static final int DATE_SORT- See Also:
-
-
Constructor Details
-
Table
public Table()Creates a new Table element with default settings. Initializes with zero cellpadding/cellspacing and creates empty header, body, and footer sections.
-
-
Method Details
-
addElement
Adds a child element to this table.If the child is a
Thead,Tbody, orTfoot, it replaces the existing section of the same type at the same position in the child list. This ensures that parsed or externally created table sections integrate correctly with the pre-created header, body, and footer sections.- Overrides:
addElementin classElement<T extends Table<T>>- Parameters:
child- the child element to add.- Returns:
- this element for method chaining
-
setBorder
public void setBorder(boolean flag) Sets whether the table displays a border.- Parameters:
flag- true to display a border, false to hide it
-
setSortable
public void setSortable(boolean sortable) Sets whether the table is sortable by clicking on column headers.- Parameters:
sortable- true to enable sorting, false to disable
-
setBorderCollapse
Sets the border-collapse property using a string value. -
setBorderCollapse
Sets the border-collapse property using an enum value. -
setBorderSpacing
Sets the border-spacing property using a string value. -
setBorderSpacing
Sets the border-spacing property using a pixel value. -
setBorderSpacing
Sets the border-spacing property with separate horizontal and vertical string values. -
setBorderSpacing
Sets the border-spacing property with separate horizontal and vertical pixel values. -
setBorderSpacing
Sets the border-spacing property using a Units object. -
setBorderSpacing
Sets the border-spacing property with separate horizontal and vertical Units values. -
setCaptionSide
Sets the caption-side property using a string value. -
setCaptionSide
Sets the caption-side property using an enum value. -
setEmptyCells
Sets the empty-cells property using a string value. -
setEmptyCells
Sets the empty-cells property using an enum value. -
setTableLayout
Sets the table-layout property using a string value. -
setTableLayout
Sets the table-layout property using an enum value. -
setCaption
Sets the table caption, replacing any existing caption.The caption is always rendered as the first child of the table element, before any column groups and table sections, as required by the HTML specification.
- Parameters:
caption- the Caption element to set
-
setCaption
Sets the table caption with the specified text, replacing any existing caption.This is a convenience method that creates a
Captionelement with the given text.- Parameters:
text- the caption text
-
getCaption
Returns the table caption, ornullif no caption has been set.- Returns:
- the Caption element, or null
-
addColgroup
Adds a column group to this table.Column groups are inserted after the caption (if present) and before the table sections (thead, tbody, tfoot), as required by the HTML specification.
- Parameters:
colgroup- the Colgroup element to add
-
setHeaderStyle
Sets the style for the table header section using a CssStyle object.- Parameters:
style- the CssStyle object to apply to the header
-
setHeaderStyle
Sets the CSS class for the table header section.- Parameters:
cssClass- the CSS class name to apply to the header
-
getHeader
Returns the table header (thead) section.- Returns:
- the Thead element for this table
-
getBody
Returns the table body (tbody) section.- Returns:
- the Tbody element for this table
-
addRow
Creates and adds a new row to the table body.- Returns:
- the newly created Tr element
-
addRow
Adds an existing row to the table body.- Parameters:
row- the Tr element to add
-
removeRow
public void removeRow(int index) Removes a row from the table body at the specified index.- Parameters:
index- the zero-based index of the row to remove
-
removeRows
public void removeRows(int start, int end) Removes a range of rows from the table body.- Parameters:
start- the starting index (inclusive)end- the ending index (exclusive)
-
removeAllRows
public void removeAllRows()Removes all rows from the table body. -
getRow
Returns the row at the specified index in the table body.- Parameters:
index- the zero-based index of the row- Returns:
- the Tr element at the specified index, or null if not found
-