AbstractDocument.BranchElement (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: javax.swing.text, class: AbstractDocument, class: BranchElement
Keywords: javax.swing.text.AbstractDocument.BranchElement class

# Class AbstractDocument.BranchElement

java.lang.Object
javax.swing.text.AbstractDocument.AbstractElement
javax.swing.text.AbstractDocument.BranchElement

All Implemented Interfaces:
  `Serializable, AttributeSet, Element, MutableAttributeSet, TreeNode`

Direct Known Subclasses:
  `DefaultStyledDocument.SectionElement, HTMLDocument.BlockElement`

Enclosing class:
  `AbstractDocument`

public class AbstractDocument.BranchElement extends AbstractDocument.AbstractElement
Implements a composite element that contains other elements.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the `java.beans` package. Please see `XMLEncoder`.

- ## Nested Class Summary

  ### Nested classes/interfaces declared in interface AttributeSet

  `AttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute`
  Modifier and Type
  Interface
  Description
  `static interface`
  `AttributeSet.CharacterAttribute`
  This interface is the type signature that is expected to be present on any attribute key that contributes to character level presentation.
  `static interface`
  `AttributeSet.ColorAttribute`
  This interface is the type signature that is expected to be present on any attribute key that contributes to presentation of color.
  `static interface`
  `AttributeSet.FontAttribute`
  This interface is the type signature that is expected to be present on any attribute key that contributes to the determination of what font to use to render some text.
  `static interface`
  `AttributeSet.ParagraphAttribute`
  This interface is the type signature that is expected to be present on any attribute key that contributes to the paragraph level presentation.

- ## Field Summary

  ### Fields declared in interface AttributeSet

  `NameAttribute, ResolveAttribute`
  Modifier and Type
  Field
  Description
  `static final Object`
  `NameAttribute`
  Attribute name used to name the collection of attributes.
  `static final Object`
  `ResolveAttribute`
  Attribute name used to identify the resolving parent set of attributes, if one is defined.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BranchElement(Element parent, AttributeSet a)`
  Constructs a composite element that initially contains no children.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Enumeration<TreeNode>`
  `children()`
  Returns the children of the receiver as an `Enumeration`.
  `boolean`
  `getAllowsChildren()`
  Returns true if the receiver allows children.
  `Element`
  `getElement(int index)`
  Gets a child element.
  `int`
  `getElementCount()`
  Gets the number of children for the element.
  `int`
  `getElementIndex(int offset)`
  Gets the child element index closest to the given model offset.
  `int`
  `getEndOffset()`
  Gets the ending offset in the model for the element.
  `String`
  `getName()`
  Gets the element name.
  `int`
  `getStartOffset()`
  Gets the starting offset in the model for the element.
  `boolean`
  `isLeaf()`
  Checks whether the element is a leaf.
  `Element`
  `positionToElement(int pos)`
  Gets the child element that contains the given model position.
  `void`
  `replace(int offset, int length, Element[] elems)`
  Replaces content with a new set of elements.
  `String`
  `toString()`
  Converts the element to a string.

  ### Methods declared in class AbstractDocument.AbstractElement

  `addAttribute, addAttributes, containsAttribute, containsAttributes, copyAttributes, dump, getAttribute, getAttributeCount, getAttributeNames, getAttributes, getChildAt, getChildCount, getDocument, getIndex, getParent, getParentElement, getResolveParent, isDefined, isEqual, removeAttribute, removeAttributes, removeAttributes, setResolveParent`
  Modifier and Type
  Method
  Description
  `void`
  `addAttribute(Object name, Object value)`
  Adds an attribute to the element.
  `void`
  `addAttributes(AttributeSet attr)`
  Adds a set of attributes to the element.
  `boolean`
  `containsAttribute(Object name, Object value)`
  Checks whether a given attribute name/value is defined.
  `boolean`
  `containsAttributes(AttributeSet attrs)`
  Checks whether the element contains all the attributes.
  `AttributeSet`
  `copyAttributes()`
  Copies a set of attributes.
  `void`
  `dump(PrintStream psOut, int indentAmount)`
  Dumps a debugging representation of the element hierarchy.
  `Object`
  `getAttribute(Object attrName)`
  Gets the value of an attribute.
  `int`
  `getAttributeCount()`
  Gets the number of attributes that are defined.
  `Enumeration<?>`
  `getAttributeNames()`
  Gets the names of all attributes.
  `AttributeSet`
  `getAttributes()`
  Gets the attributes for the element.
  `TreeNode`
  `getChildAt(int childIndex)`
  Returns the child `TreeNode` at index `childIndex`.
  `int`
  `getChildCount()`
  Returns the number of children `TreeNode`'s receiver contains.
  `Document`
  `getDocument()`
  Retrieves the underlying model.
  `int`
  `getIndex(TreeNode node)`
  Returns the index of `node` in the receivers children.
  `TreeNode`
  `getParent()`
  Returns the parent `TreeNode` of the receiver.
  `Element`
  `getParentElement()`
  Gets the parent of the element.
  `AttributeSet`
  `getResolveParent()`
  Gets the resolving parent.
  `boolean`
  `isDefined(Object attrName)`
  Checks whether a given attribute is defined.
  `boolean`
  `isEqual(AttributeSet attr)`
  Checks whether two attribute sets are equal.
  `void`
  `removeAttribute(Object name)`
  Removes an attribute from the set.
  `void`
  `removeAttributes(Enumeration<?> names)`
  Removes a set of attributes for the element.
  `void`
  `removeAttributes(AttributeSet attrs)`
  Removes a set of attributes for the element.
  `void`
  `setResolveParent(AttributeSet parent)`
  Sets the resolving parent.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### BranchElement

    public BranchElement(Element parent, AttributeSet a)
    Constructs a composite element that initially contains no children.
    Parameters:
      `parent` - The parent element
      `a` - the attributes for the element
    Since:
      1.4

- ## Method Details

  - ### positionToElement

    public Element positionToElement(int pos)
    Gets the child element that contains the given model position.
    Parameters:
      `pos` - the position >= 0
    Returns:
      the element, null if none

  - ### replace

    public void replace(int offset, int length, Element[] elems)
    Replaces content with a new set of elements.
    Parameters:
      `offset` - the starting offset >= 0
      `length` - the length to replace >= 0
      `elems` - the new elements

  - ### toString

    public String toString()
    Converts the element to a string.
    Overrides:
      `toString` in class `Object`
    Returns:
      the string

  - ### getName

    public String getName()
    Gets the element name.
    Specified by:
      `getName` in interface `Element`
    Overrides:
      `getName` in class `AbstractDocument.AbstractElement`
    Returns:
      the element name

  - ### getStartOffset

    public int getStartOffset()
    Gets the starting offset in the model for the element.
    Specified by:
      `getStartOffset` in interface `Element`
    Specified by:
      `getStartOffset` in class `AbstractDocument.AbstractElement`
    Returns:
      the offset >= 0
    See Also:
      - `Document`
      - `AbstractDocument`

  - ### getEndOffset

    public int getEndOffset()
    Gets the ending offset in the model for the element.
    Specified by:
      `getEndOffset` in interface `Element`
    Specified by:
      `getEndOffset` in class `AbstractDocument.AbstractElement`
    Returns:
      the offset >= 0
    Throws:
      `NullPointerException` - if this element has no children
    See Also:
      - `Document`
      - `AbstractDocument`

  - ### getElement

    public Element getElement(int index)
    Gets a child element.
    Specified by:
      `getElement` in interface `Element`
    Specified by:
      `getElement` in class `AbstractDocument.AbstractElement`
    Parameters:
      `index` - the child index, >= 0 && < getElementCount()
    Returns:
      the child element, null if none

  - ### getElementCount

    public int getElementCount()
    Gets the number of children for the element.
    Specified by:
      `getElementCount` in interface `Element`
    Specified by:
      `getElementCount` in class `AbstractDocument.AbstractElement`
    Returns:
      the number of children >= 0

  - ### getElementIndex

    public int getElementIndex(int offset)
    Gets the child element index closest to the given model offset.
    Specified by:
      `getElementIndex` in interface `Element`
    Specified by:
      `getElementIndex` in class `AbstractDocument.AbstractElement`
    Parameters:
      `offset` - the offset >= 0
    Returns:
      the element index >= 0

  - ### isLeaf

    public boolean isLeaf()
    Checks whether the element is a leaf.
    Specified by:
      `isLeaf` in interface `Element`
    Specified by:
      `isLeaf` in interface `TreeNode`
    Specified by:
      `isLeaf` in class `AbstractDocument.AbstractElement`
    Returns:
      true if a leaf

  - ### getAllowsChildren

    public boolean getAllowsChildren()
    Returns true if the receiver allows children.
    Specified by:
      `getAllowsChildren` in interface `TreeNode`
    Specified by:
      `getAllowsChildren` in class `AbstractDocument.AbstractElement`
    Returns:
      true if the receiver allows children, otherwise false

  - ### children

    public Enumeration<TreeNode> children()
    Returns the children of the receiver as an `Enumeration`.
    Specified by:
      `children` in interface `TreeNode`
    Specified by:
      `children` in class `AbstractDocument.AbstractElement`
    Returns:
      the children of the receiver