Class TextConf

java.lang.Object
swingtree.style.TextConf

@Immutable public final class TextConf extends Object
An immutable configuration type which holds custom text as well as placement and font properties used for rendering text onto a Swing component.
This objects is exposed inside the ComponentStyleDelegate.text(Configurator) as a way to configure custom text properties of a component as part of the style API exposed by UIForAnySwing.withStyle(Styler).

Here a simple usage example which demonstrates how to render text onto the top edge of a JPanel:


      UI.panel()
      .withStyle(conf -> conf
          .prefSize(180, 100)
          .background(Color.CYAN)
          .text(textConf -> textConf
              .content("Hello World!")
              .placement(UI.Placement.TOP)
              .font( fontConf -> fontConf.color(Color.DARK_GRAY).size(20) )
          )
      )
  
In this small example you can see the usage of content(String), placement(UI.Placement) and font(Configurator). But there are much more properties available to configure the text rendering as part of the style API.

Here a full list of all available properties with their respective meaning and default values:

Use none() to access the null object of the TextConf type. It is a convenient way to represent a no-op configuration object which will not have any effect when applied to a component.
  • Field Details

    • DEFAULT_LAYER

      public static UI.Layer DEFAULT_LAYER
  • Method Details

    • content

      public TextConf content(String textString)
      Returns a new TextConf object with the given text content.
      Parameters:
      textString - The text content to be rendered onto the component.
      Returns:
      A new TextConf object with the given text content.
    • font

      public TextConf font(Configurator<FontConf> fontConfFunction)
      Returns a new TextConf object with the given font configuration defined by a configurator function which takes a FontConf object and returns an updated FontConf object with the desired font properties.
      Parameters:
      fontConfFunction - A function which takes the current font configuration and returns a new font configuration with the desired properties.
      Returns:
      A new TextConf object with the given font configuration.
    • font

      public TextConf font(Font font)
      Returns a new TextConf object with the given font.
      Parameters:
      font - The font to be used for rendering the text onto the component.
      Returns:
      A new TextConf object with the given font.
    • clipTo

      public TextConf clipTo(UI.ComponentArea clipArea)
      Returns a new TextConf object with the given clip area defined by a UI.ComponentArea enum. Text positioned outside the clip area will not be visible.
      Parameters:
      clipArea - The clip area where the text should be rendered onto the component.
      Returns:
      A new TextConf object with the given clip area.
    • placementBoundary

      public TextConf placementBoundary(UI.ComponentBoundary placementBoundary)
      Returns a new TextConf object with the given placement boundary defined by a UI.ComponentBoundary enum. The placement boundary defines the boundary of the component onto which the text placement should be bound to.

      The following placement boundaries are available:

      Parameters:
      placementBoundary - The placement boundary of the component.
      Returns:
      A new TextConf object with the given placement boundary.
    • placement

      public TextConf placement(UI.Placement placement)
      Returns an updated TextConf object with the given placement, defined by a UI.Placement enum. The placement defines where the text should be placed according to the placementBoundary(UI.ComponentBoundary).

      The following placements are available:

      Parameters:
      placement - The placement of the text, defined by a UI.Placement enum.
      Returns:
      An updated TextConf object with the desired placement.
    • offset

      public TextConf offset(int x, int y)
      Returns a TextConf object updated with an x and y placement offset. The offset holds the x and y placement offset of the text. This property is great for making fine adjustments to the text placement. However, for a more robust alignment of the text, it is recommended to use the placement(UI.Placement) and placementBoundary(UI.ComponentBoundary) properties as a first choice.
      Parameters:
      x - The x placement offset of the text.
      y - The y placement offset of the text.
      Returns:
      An updated TextConf object with the given offset.
    • simplified

      public TextConf simplified()
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object