Color

Color represents color values used throughout JDance. It supports CSS color strings, RGB channels, and alpha transparency for backgrounds and other styling.

For the complete API reference, visit https://doc.jdance.org.

Overview

Named colors and hexadecimal strings are convenient when matching an established palette. Numeric RGB values are useful when colors come from calculations or stored channel data.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setGap(5);
layout.add(new Text("Named")).setPadding(8).setBgColor(new Color("lightblue"));
layout.add(new Text("Hex")).setPadding(8).setBgColor(new Color("#E4F5E9"));
layout.add(new Text("RGB")).setPadding(8).setBgColor(new Color(255,240,216));
RESULT
Named
Hex
RGB

The preview above uses a small amount of space so the behavior is visible even in a narrow documentation panel.

Opacity and layering

A four-channel color adds alpha transparency. With a partially transparent background, the color behind the component contributes to the final appearance.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setGap(6);
layout.setBackground(new Color("#DCEEFF"));
layout.add(new Text("Opaque")).setPadding(8).setBgColor(new Color(123,44,191,255));
layout.add(new Text("Half alpha")).setPadding(8).setBgColor(new Color(123,44,191,128));
RESULT
Opaque
Half alpha

Contrast and meaning

Foreground and background colors should remain easy to distinguish. Color can indicate information, success or caution, but it should not be the sole carrier of meaning.

Foreground and background

The same idea can also be expressed as a compact Java snippet without requiring a live preview.

CODE
Text text = new Text("Notice");
text.setFont(new Font().setColor(new Color("#263238")));
text.setBackground(new Color("#E4F5E9"));

Practical guidance

For predictable results, use opaque foreground text and reserve transparency for accents and layered backgrounds.

Full API reference

These examples focus on the day-to-day use of Color. The full API documentation contains additional options, inherited properties and complete method signatures.

Visit https://doc.jdance.org for the full reference.