Size

Size provides special sizing values for JDance layout cells. Instead of choosing a fixed pixel height, a cell can let its content determine its height or use automatic sizing.

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

Overview

Size.CONTENT is useful for rows containing headings, labels, and descriptions. A content-sized cell occupies the height necessary to show its component.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setGap(6);
layout.add(new Text("Title")).setHeight(Size.CONTENT).setPadding(8).setBgColor(new Color("#DCEEFF"));
layout.add(new Text("Description")).setHeight(Size.CONTENT).setPadding(8).setBgColor(new Color("#E4F5E9"));
RESULT
Title
Description

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

Combining sizing strategies

Different cells can use different sizing rules within the same layout. This is useful when a heading should fit its text while another area should participate in automatic sizing.

CODE
BasicLayout layout = new BasicLayout(BasicLayout.Direction.VERTICAL);
layout.setRelativeWidth(100);
layout.setGap(6);
layout.add(new Text("Content")).setHeight(Size.CONTENT).setPadding(8).setBgColor(new Color("#DCEEFF"));
layout.add(new Text("Auto")).setHeight(Size.AUTO).setPadding(8).setBgColor(new Color("#FFF0D8"));
RESULT
Content
Auto

Fixed versus automatic sizing

Fixed dimensions are predictable but can clip or crowd content. Content-driven dimensions accommodate variation, including longer labels and text wrapping. Automatic sizing is another option determined by the layout context.

Sizing a heading

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

CODE
layout.add(new Text("Heading"))
        .setHeight(Size.CONTENT);

Practical guidance

Remember that Size.CONTENT applies to the cell, while the component itself may also have width or height settings. The surrounding layout still determines the available space.

Full API reference

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

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