Package swingtree.style
Class TextConf
java.lang.Object
swingtree.style.TextConf
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
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:
- Content
You can set this property through
content(String)
. This is the actual text content that should be rendered onto the component. It's default value is an empty string, in which case this configuration object will not have any effect. - Font
The
FontConf
object is its own rich configuration object which holds all font properties like size, style, color, etc. You can configure it throughfont(Configurator)
.
The default font configuration isFontConf.none()
. - Clip Area
The clip area is an enum the area of the component where the text should be
rendered. So the text will only be visible within this area.
You can configure it throughclipTo(UI.ComponentArea)
.
The default clip area isUI.ComponentArea.INTERIOR
. - Placement Boundary
The placement boundary is an enum which defines the boundary of the component
onto which the text placement should be bound to.
You can configure it through
placementBoundary(UI.ComponentBoundary)
.
The default placement boundary isUI.ComponentBoundary.INTERIOR_TO_CONTENT
, which honours the padding of the component. If you want to ignore the padding and place the text directly after the border of the component, you can set it toUI.ComponentBoundary.BORDER_TO_INTERIOR
. - Placement
The placement is an enum which defines where the text should be placed
according to the
placementBoundary(UI.ComponentBoundary)
. You can configure it throughplacement(UI.Placement)
.
The default placement isUI.Placement.CENTER
. - Offset
The offset holds the x and y placement offset of the text.
You can configure it through
offset(Offset)
oroffset(int, int)
.
The default offset isOffset.none()
(0, 0). 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 theplacement(UI.Placement)
andplacementBoundary(UI.ComponentBoundary)
properties as a first choice.
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionclipTo
(UI.ComponentArea clipArea) Returns a newTextConf
object with the given clip area defined by aUI.ComponentArea
enum.Returns a newTextConf
object with the given text content.boolean
Returns a newTextConf
object with the given font.font
(Configurator<FontConf> fontConfFunction) int
hashCode()
offset
(int x, int y) Returns aTextConf
object updated with an x and y placement offset.placement
(UI.Placement placement) Returns an updatedTextConf
object with the given placement, defined by aUI.Placement
enum.placementBoundary
(UI.ComponentBoundary placementBoundary) Returns a newTextConf
object with the given placement boundary defined by aUI.ComponentBoundary
enum.toString()
-
Field Details
-
DEFAULT_LAYER
-
-
Method Details
-
content
Returns a newTextConf
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
Returns a newTextConf
object with the given font configuration defined by a configurator function which takes aFontConf
object and returns an updatedFontConf
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
Returns a newTextConf
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
Returns a newTextConf
object with the given clip area defined by aUI.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
Returns a newTextConf
object with the given placement boundary defined by aUI.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:
UI.ComponentBoundary.OUTER_TO_EXTERIOR
- The outermost boundary of the entire component, including any margin that might be applied.UI.ComponentBoundary.EXTERIOR_TO_BORDER
- The boundary located after the margin but before the border. This tightly wraps the entireUI.ComponentArea.BODY
.UI.ComponentBoundary.BORDER_TO_INTERIOR
- The boundary located after the border but before the padding. It represents the edge of the component's interior.UI.ComponentBoundary.INTERIOR_TO_CONTENT
- The boundary located after the padding. It represents the innermost boundary of the component, where the actual content of the component begins, typically the sub-components of the component.
- Parameters:
placementBoundary
- The placement boundary of the component.- Returns:
- A new
TextConf
object with the given placement boundary.
-
placement
Returns an updatedTextConf
object with the given placement, defined by aUI.Placement
enum. The placement defines where the text should be placed according to theplacementBoundary(UI.ComponentBoundary)
.The following placements are available:
UI.Placement.TOP
- Placed centered at the top edge of the component.UI.Placement.BOTTOM
- Placed centered at the bottom edge of the component.UI.Placement.LEFT
- At the left center edge of the component.UI.Placement.RIGHT
- The right center edge of the component.UI.Placement.CENTER
- Placed on the center of the edges defined by theUI.ComponentBoundary
.UI.Placement.TOP_LEFT
- Placed at the top left corner of the component.UI.Placement.TOP_RIGHT
- Placed at the top right corner of the component.UI.Placement.BOTTOM_LEFT
- Placed at the bottom left corner of the component.UI.Placement.BOTTOM_RIGHT
- Placed at the bottom right corner of the component.
- Parameters:
placement
- The placement of the text, defined by aUI.Placement
enum.- Returns:
- An updated
TextConf
object with the desired placement.
-
offset
Returns aTextConf
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 theplacement(UI.Placement)
andplacementBoundary(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
-
equals
-
hashCode
public int hashCode() -
toString
-