GridLayout

GridLayout arranges components in rows and columns.

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

Overview

Two columns of small cells.

CODE
GridLayout grid = new GridLayout(2);
grid.setGap(6);
grid.add(new Text("One")).setPadding(8).setBgColor(new Color("#DCEEFF"));
grid.add(new Text("Two")).setPadding(8).setBgColor(new Color("#E4F5E9"));
grid.add(new Text("Three")).setPadding(8).setBgColor(new Color("#FFF0D8"));
grid.add(new Text("Four")).setPadding(8).setBgColor(new Color("#F5E5F8"));
RESULT
One
Two
Three
Four

Alternating row backgrounds

Set the default background for odd and even rows. The first row is odd. A cell's own setBackground() overrides the row background.

CODE
GridLayout grid = new GridLayout(3);
grid.setRelativeWidth(100);
grid.setCellPadding(14);
grid.setCellBorder(new Border().setWidth(1).setColor(new Color("#D8DEE8")));
grid.setOddRowBackground(new Color("#FFFFFF"));
grid.setEvenRowBackground(new Color("#EDF1F5"));

grid.add(new Text("Name"));
grid.add(new Text("Role"));
grid.add(new Text("Status"));

grid.add(new Text("Alex"));
grid.add(new Text("Developer"));
grid.add(new Text("Active"));

grid.add(new Text("Sam"));
grid.add(new Text("Designer"));
grid.add(new Text("Active")).setBackground(new Color("#DCE9D9"));

grid.add(new Text("Taylor"));
grid.add(new Text("Manager"));
grid.add(new Text("Pending"));
RESULT
Name
Role
Status
Alex
Developer
Active
Sam
Designer
Active
Taylor
Manager
Pending