Class HBox

All Implemented Interfaces:
Dimensions
Direct Known Subclasses:
Columns

public class HBox extends Box
Horizontal sequence of elements.
  • Constructor Details

  • Method Details

    • ofWidth

      public static HBox ofWidth(List<Element> elements, long width)
      Make a new HBox that's forced to be the specified width.
    • leftAligned

      public static HBox leftAligned(Element element, long width)
      Make a new HBox with the content left-aligned in a box of the specified width.
    • centered

      public static HBox centered(Element element, long width)
      Make a new HBox with the content centered in a box of the specified width.
    • rightAligned

      public static HBox rightAligned(Element element, long width)
      Make a new HBox with the content right-aligned in a box of the specified width.
    • getElements

      public List<Element> getElements()
      Do not modify this list.
    • isEmpty

      public boolean isEmpty()
      Whether this horizontal box is empty, i.e., has no elements in it.
    • getOnlyString

      public String getOnlyString()
      If the HBox contains only one element, and this element is a Text, then returns the text of this Text. If the HBox is empty, returns an empty string.
      Throws:
      IllegalArgumentException - if one of the above conditions do not hold.
    • makeOnlyString

      public static HBox makeOnlyString(String text, SizedFont font)
      Make an HBox that contains only a Text with the given string, font, and font size.
    • layOutHorizontally

      public long layOutHorizontally(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a horizontal sequence.
      Overrides:
      layOutHorizontally in class Box
      Parameters:
      x - the left-most point of the element.
      y - the baseline of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move right afterward.
      Throws:
      IOException
    • layOutVertically

      public long layOutVertically(long x, long y, org.apache.pdfbox.pdmodel.PDPageContentStream contents) throws IOException
      Description copied from class: Element
      Add the element to the contents as part of a vertical sequence.
      Overrides:
      layOutVertically in class Box
      Parameters:
      x - the left-most point of the element.
      y - the upper-left point of the element.
      contents - the stream to add the element to.
      Returns:
      how much to move down afterward.
      Throws:
      IOException
    • visit

      public void visit(Consumer<Element> consumer)
      Description copied from class: Element
      Calls the consumer on this element and all child elements in pre-order. The default implementation just calls the consumer on this element.
      Overrides:
      visit in class Element
    • println

      public void println(PrintStream stream, String indent)
      Description copied from class: Element
      Pretty prints the element to the PrintWriter with the given indent. The method must print its own newline.
      Overrides:
      println in class Element
    • toTextString

      public String toTextString()
      Description copied from class: Element
      Return a text version of the element, ideally containing only the text of the element and its children.
      Overrides:
      toTextString in class Element
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object