Text is one of the most frequently used components in JDance. It displays textual content and allows you to control its appearance directly from Java.
You can configure typography, colors, spacing, and other visual properties without writing HTML or CSS yourself.
Text can be used independently or placed inside layouts, panels, forms, and other components.
Creating text is straightforward. Pass the content to the Text constructor and configure the component as needed.
The following example demonstrates a simple text component with a background color and padding.
Text works like other JDance components. It can be added to a layout, styled individually, and combined with other components to create an interface.
For example, you can add several Text components to a VerticalLayout to create a group of labels or descriptions.
Text supports font configuration through the Font class.
You can change properties such as the font size, weight, and color. This makes it possible to use the same component for headings, descriptions, labels, and other textual elements.
The following example demonstrates different typography settings.
The Font object groups typography settings together, keeping the configuration separate from the text content.
This is particularly useful when the same typography needs to be reused across multiple components.
Text can also use CSS text-shadow effects to create emphasis or visual depth.
A text shadow is different from a component shadow. It follows the shape of the characters rather than the rectangular boundaries of the component.
The example below demonstrates two different shadow styles.
In these examples, addExplicitStyle() applies the CSS text-shadow property directly to the Text component.
The first effect adds a subtle offset shadow, while the second produces a soft glow around the characters.
Text shadows can be useful for headings and decorative text, but they should be used sparingly in interfaces where readability is important.
Text components can be combined with cell styling to create reusable interface patterns.
For example, rather than giving the Text component a background color, you can apply the background and padding to the containing layout cell.
This separates the appearance of the text from the appearance of its surrounding cell.
It is especially useful when building cards, notifications, forms, and other structured interface elements.
Text provides additional configuration options beyond the examples demonstrated here.
For the complete reference covering Text, Font, and inherited component functionality, visit https://doc.jdance.org.