Programmatic layouts
Slots on a Pane can also be filled directly by slot index or coordinate, without a character template, or you can pick an ordered set of slots first and fill them one by one. Once the menu is open, all of these methods remain callable.
For menus with a fixed shape, the character layout and filling content styles read better, because the template itself is the menu's picture. Use this page's methods in two situations: the layout can only be computed at runtime, or certain slots must be replaced after the menu opens.
Filling slotsâ
Creating a blank Paneâ
When the size is only known at runtime, create a blank Pane first and add content afterwards. Below, the row count follows the reward count, nine rewards per row:
List<ItemStack> rewards = List.of(
new ItemStack(Material.DIAMOND),
new ItemStack(Material.EMERALD),
new ItemStack(Material.GOLD_INGOT)
);
int rows = Math.clamp((rewards.size() + 8) / 9, 1, 6);
Pane pane = Pane.empty(9, rows);
| Entry point | Resulting Pane |
|---|---|
Pane.empty(width, height) | A blank Pane |
Pane.filled(width, height, item) | Every slot holds the same Item |
Pane.single(item) | One slot holding this Item |
Pane.builder(width, height) | A blank-layout Builder that can still set background and freeze |
Placing by positionâ
setItem places an Item by slot index or coordinate; the conversion between them is covered in Slots and coordinates:
Pane pane = Pane.empty(9, 3);
pane.setItem(13, Item.simple(new ItemStack(Material.BOOK))); // slot 13, dead center
pane.setItem(0, 2, Item.simple(new ItemStack(Material.ARROW))); // coordinate (0, 2), bottom-left
| Method | Purpose |
|---|---|
setItem(slot, item), setItem(x, y, item) | Put an Item in this slot |
setElement(slot, element), setElement(x, y, element) | Put an Element in this slot |
setPane(slot, pane, paneSlot) | Make this slot display slot paneSlot of another Pane |
Calling these after the menu opens updates every Window currently showing the Pane immediately. Below, the chest turns into gray dye after the first click, marking it as claimed:
Pane pane = Pane.empty(9, 1);
Item claimed = Item.simple(new ItemStack(Material.GRAY_DYE));
pane.setItem(4, Item.builder()
.setItemProviderConstant(new ItemStack(Material.CHEST))
.addClickHandler(click -> pane.setItem(4, claimed))
.build());
If the instance placed is the same one as before, the Pane considers the content unchanged and does not refresh. When the content has not changed but needs to be drawn again, call pane.dirty(slot).
setPane can establish nesting after both Panes exist, so cycles are possible: a slot of A displays B, and a slot of B displays A. When a Window tries to display such a slot, it throws an IllegalStateException.
Filling in bulkâ
The fill methods fill an area with one Item:
| Method | Fill range |
|---|---|
fill(item) | The whole Pane |
fill(start, end, item) | Slots start through end - 1 |
fillRow(row, item) | One row |
fillColumn(column, item) | One column |
fillBorders(item) | The ring around the edge |
fillRectangle(x, y, width, height, item) | A rectangle with its top-left at (x, y) |
fillRectangle(x, y, pane) | Nest a whole other Pane into the area with its top-left at (x, y) |
Every method accepts one extra trailing replaceExisting argument. Omitted, it defaults to true and overwrites existing content; pass false to fill only slots that are still empty. Below, the border and a book go in first, then the remaining slots are filled with false:
Item border = Item.simple(new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
Item filler = Item.simple(new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
Pane pane = Pane.empty(9, 5);
pane.fillBorders(border);
pane.setItem(4, 2, Item.simple(new ItemStack(Material.BOOK)));
pane.fill(filler, false);

-fillBorders(border)24
+fill(filler, false)20
BsetItem(4, 2, ...)1
Without false, fill would overwrite the border and the book with gray glass panes too.
Appending to empty slotsâ
addItems walks from slot 0 in reading order, left to right then top to bottom, putting each Item into the next empty slot and skipping slots that already have content. Continuing the blank Pane example, the rewards go in one after another:
for (ItemStack reward : rewards) {
pane.addItems(Item.simple(reward));
}
Once the empty slots run out, leftover Items are neither placed nor reported. Lists that may exceed one screen belong in Pagination Page.
Slot sequencesâ
A SlotSequence is an ordered set of slots. Pick the slots first, then generate content for each with setElements. This fits cases where every slot's content differs and the placement order matters.
Creating a slot sequenceâ
| Form | Slots selected, in order |
|---|---|
SlotSequence.all(size) | All slots, left to right, top to bottom |
SlotSequence.row(size, row) | One full row, left to right |
SlotSequence.column(size, column) | One full column, top to bottom |
SlotSequence.range(size, start, end) | Slots start through end - 1 |
SlotSequence.rectangle(size, x, y, width, height) | A rectangle, collected row by row |
SlotSequence.borders(size) | The ring around the edge |
SlotSequence.of(size, slot...) | The given slots, in the given order |
SlotSequence.concat(sequence...) | Several groups joined into one, with no duplicate slots |
pane.slots("G") | The slots occupied by identifier G in the template |
size is the Pane's size, obtained with pane.size().
Generating content along the sequenceâ
setElements generates content for every slot in the sequence the same way an ElementSupplier does; occurrence is the slot's position within the sequence:
Pane pane = Pane.empty(9, 3);
SlotSequence middle = SlotSequence.row(pane.size(), 1);
// The second row gets 1 through 9 sheets of paper, left to right.
pane.setElements(
middle,
(slots, occurrence) -> Element.item(Item.simple(new ItemStack(Material.PAPER, occurrence + 1))),
true
);
The last argument is again replaceExisting.
A SlotSequence is bound to one PaneSize at creation. Using it on a Pane of a different size makes setElements throw an IllegalArgumentException.
If content generation throws, the Pane is left untouched and the exception propagates to the caller as is.
Reordering or filteringâ
transform(SlotPattern) reorders a sequence or keeps only part of it. SlotPatterns provides a few:
| Form | Result |
|---|---|
SlotPatterns.ROW_MAJOR | Row by row, left to right within each row |
SlotPatterns.COLUMN_MAJOR | Column by column, top to bottom within each column |
SlotPatterns.CHECKERBOARD_EVEN | Only slots where x + y is even, one color of a checkerboard |
SlotPatterns.CHECKERBOARD_ODD | Only slots where x + y is odd |
Template areas can be treated the same way. The builder's addModifier runs after the Pane is created, so this page's methods can continue on top of the template. slots also accepts a SlotPattern; below, the G area is numbered column by column:
Pane pane = Pane.builder(
"#########",
"#GGGGGGG#",
"#GGGGGGG#",
"#########"
)
.addModifier(target -> target.setElements(
target.slots(SlotPatterns.COLUMN_MAJOR, "G"),
(slots, occurrence) -> Element.item(Item.simple(new ItemStack(Material.PAPER, occurrence + 1))),
true
))
.build();
Numbering runs downward first, then rightward: the first column holds 1 and 2, the second 3 and 4:
#empty22
GCOLUMN_MAJOR order14
For other orders, implement SlotPattern yourself and hand the candidate slots to the output in whatever order you want.
project makes a set of slots follow a Signal-backed list: when the list updates, content is placed again automatically. See Signals in the UI.