Class Spacer<T extends Spacer<T>>


public class Spacer<T extends Spacer<T>> extends StyledElement<T>
Represents a layout spacer element that creates vertical or horizontal spacing in a document.

The Spacer class extends StyledElement to provide a simple way to create blank space for layout purposes. It renders as an invisible <div> element with specified dimensions and zero font size. This is useful for creating vertical spacing between elements or horizontal spacing in layouts.

Features:

  • Creates vertical or horizontal spacing
  • Configurable width and height
  • Invisible content (zero font size and line height)
  • Simple alternative to margin/padding CSS
  • Renders as a styled div element
  • Useful for legacy layout techniques

Usage:


 // Vertical spacer (1px wide, 20px tall)
 Spacer verticalGap = new Spacer(20);
 // Creates vertical space between elements

 // Larger vertical spacer
 Spacer bigGap = new Spacer(50);

 // Horizontal and vertical spacer (100px wide, 30px tall)
 Spacer customSpacer = new Spacer(100, 30);

 // Using in a layout
 Div container = new Div();
 container.addElement(new Paragraph("First paragraph"));
 container.addElement(new Spacer(15));  // 15px vertical gap
 container.addElement(new Paragraph("Second paragraph"));
 container.addElement(new Spacer(25));  // 25px vertical gap
 container.addElement(new Paragraph("Third paragraph"));

 // Note: Modern layouts should typically use CSS margin/padding instead
 // This class is useful for backward compatibility and simple spacing needs
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Spacer

      public Spacer(int height)
      Constructs a new vertical Spacer element with the specified height.

      Creates an invisible spacer that is 1 pixel wide and the specified height. This is typically used to create vertical spacing between elements. The spacer has zero font size and line height to ensure it doesn't contain any visible content.

      Parameters:
      height - the height of the spacer in pixels
    • Spacer

      public Spacer(int width, int height)
      Constructs a new Spacer element with the specified width and height.

      Creates an invisible spacer with custom dimensions. This can be used for both vertical and horizontal spacing, or to create a blank area of specific size. The spacer has zero font size and line height to ensure it doesn't contain any visible content.

      Parameters:
      width - the width of the spacer in pixels
      height - the height of the spacer in pixels