Aller au contenu
galdurdocs

ListHandle

classclient uniquementdepuis 0.1.0

com.galdurstudio.galdurui.api.window.ListHandle

Pas encore traduit : texte d’origine en anglais.

Handle to a scrolling list of a GaldurWindow: its lines, the selected line and the scroll position.

Returned by GaldurWindow.addList(...). As with CheckboxHandle, the state lives here, not in the shown widget: it survives resizes, and the lines can change at any time, even while the window is open, without rebuilding the screen.

Example.java
ListHandle ores = window.addList(5);ores.addLine(Component.literal("Iron"));ores.addLine(Component.literal("Gold"));ores.onSelect(index -> System.out.println("Chosen: " + index));

The list width is computed when the screen is built, from the longest line. A longer line added later is clipped at the edge until the next rebuild (resize, or an element added to the window). Like any ElementHandle, the list can be disabled, hidden or given a tooltip.

Call on the client thread.

public class ListHandle extends ElementHandle
PAQUETapi.window
CÔTÉclient uniquement
HÉRITE DEElementHandle

MEMBRES · 15

Méthodes 15

addLine

public void addLine(Component line)

Adds a line at the end of the list.

PARAMÈTRES

lineComponentthe line text

setLines

public void setLines(List<Component> newLines)

Replaces all lines, for instance to show a search result. The selection is cleared, since its index would now point at another line; if there was one, onSelect() is called with -1.

PARAMÈTRES

newLinesList<Component>the new lines, in display order; the list is copied

clearLines

public void clearLines()

Removes all lines, and the selection with them.

getLines

public List<Component> getLines()

RENVOIEList<Component> — the lines, read-only; the view follows changes to the list

getSelected

public int getSelected()

RENVOIEint — the index of the selected line, or -1 if none

setSelected

public void setSelected(int index)

Selects a line. When the value really changes, the action given to onSelect() is called, whether the change comes from the player or from code.

PARAMÈTRES

indexintthe line index, or -1 for none; an index outside the list counts as -1

onSelect

public void onSelect(IntConsumer action)

Sets the action called when the selection changes. Only one action is kept: a new call replaces the previous one. It receives the line index, or -1.

PARAMÈTRES

actionIntConsumercalled on every selection change

getScroll

public double getScroll()

RENVOIEdouble — the scroll offset, in pixels from the top of the content

setScroll

public void setScroll(double scroll)

Remembers the scroll offset, to restore it when the screen is rebuilt. Called by the shown widget; a mod usually does not need it.

PARAMÈTRES

scrolldoubleoffset, in pixels from the top of the content
public void setEnabled(boolean enabled)

Enables or disables the element. No effect if it is already in that state.

PARAMÈTRES

enabledbooleanfalse to disable it
public boolean isEnabled()

RENVOIEboolean — true if the element is enabled (the default)

public void setVisible(boolean visible)

Shows or hides the element. Hidden, it frees its space in the window. No effect if it is already in that state.

PARAMÈTRES

visiblebooleanfalse to hide it
public boolean isVisible()

RENVOIEboolean — true if the element is shown (the default)

public void setTooltip(Component tooltip)

Sets the text shown when the element is hovered.

PARAMÈTRES

tooltipComponentthe tooltip text, or null to remove it
public Component getTooltip()

RENVOIEComponent — the tooltip text, or null if none

© 2026 Galdur Studio · galdurstudio.com · Discord · LGPL-3.0-onlyProduit non officiel. Non approuvé par Mojang ou Microsoft, ni associé à eux.