Padding

Padding is the space inside a component or layout, between its content and its surrounding edges. It differs from a layout gap, which separates neighboring cells.

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

Overview

The simplest form applies the same amount of internal space to every side. It is useful for labels, panels, and card-like content.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setBackground(new Color("#DCEEFF"));
layout.setPadding(new Padding(16));
layout.add(new Text("Padded content"));
RESULT
Padded content

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

Independent sides

A four-value Padding uses top, right, bottom, left order. Unequal values are helpful when a design requires more horizontal breathing room than vertical space.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setBackground(new Color("#E4F5E9"));
layout.setPadding(new Padding(6,16,20,8));
layout.add(new Text("Uneven padding"));
RESULT
Uneven padding

Padding compared with gap

Padding adds space within one element; gap controls separation between adjacent children. In a compact card, both may be used together, but they address different concerns.

Setting all four sides

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

CODE
Padding padding = new Padding(10,20,10,20);
layout.setPadding(padding);

Practical guidance

Large padding values consume available width. In a narrow RESULT panel, keep examples modest so their content remains readable.

Full API reference

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

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