Class ActionRow
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.components.ActionRow
-
- All Implemented Interfaces:
Iterable<ItemComponent>
,Component
,LayoutComponent
,SerializableData
public class ActionRow extends Object implements LayoutComponent
One row of components.- See Also:
ItemComponent
,LayoutComponent
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.interactions.components.Component
Component.Type
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ActionRow
asDisabled()
Returns a new instance of this LayoutComponent with all components set to disabled.ActionRow
asEnabled()
Returns a new instance of this LayoutComponent with all components set to enabled.boolean
equals(Object obj)
static ActionRow
fromData(DataObject data)
Load ActionRow from serialized representation.List<ItemComponent>
getComponents()
Mutable list of components in this ActionRow.Component.Type
getType()
The type of component.int
hashCode()
Iterator<ItemComponent>
iterator()
static ActionRow
of(Collection<? extends ItemComponent> components)
Create one row ofcomponents
.static ActionRow
of(ItemComponent... components)
Create one row ofcomponents
.static List<ActionRow>
partitionOf(Collection<? extends ItemComponent> components)
Partitions the providedcomponents
into a list of ActionRow instances.static List<ActionRow>
partitionOf(ItemComponent... components)
Partitions the providedcomponents
into a list of ActionRow instances.DataObject
toData()
SerializedDataObject
for this object.String
toString()
ActionRow
withDisabled(boolean disabled)
Returns a new instance of this LayoutComponent with all components set to disabled/enabled.-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.LayoutComponent
getActionComponents, getButtons, isDisabled, isEmpty, isEnabled, isValid, updateComponent, updateComponent
-
-
-
-
Method Detail
-
fromData
@Nonnull public static ActionRow fromData(@Nonnull DataObject data)
Load ActionRow from serialized representation.
Inverse oftoData()
.- Parameters:
data
- Serialized version of an action row- Returns:
- ActionRow instance
- Throws:
ParsingException
- If the provided data is not a valid action rowIllegalArgumentException
- If the data is null or the type is not 1
-
of
@Nonnull public static ActionRow of(@Nonnull Collection<? extends ItemComponent> components)
Create one row ofcomponents
.
You cannot currently mix different types of components and each type has its own maximum defined byComponent.Type.getMaxPerRow()
.- Parameters:
components
- The components for this action row- Returns:
- The action row
- Throws:
IllegalArgumentException
- If anything is null, empty, or an invalid number of components are provided
-
of
@Nonnull public static ActionRow of(@Nonnull ItemComponent... components)
Create one row ofcomponents
.
You cannot currently mix different types of components and each type has its own maximum defined byComponent.Type.getMaxPerRow()
.- Parameters:
components
- The components for this action row- Returns:
- The action row
- Throws:
IllegalArgumentException
- If anything is null, empty, or an invalid number of components are provided
-
partitionOf
@Nonnull public static List<ActionRow> partitionOf(@Nonnull Collection<? extends ItemComponent> components)
Partitions the providedcomponents
into a list of ActionRow instances.
This will split the provided components byComponent.Type.getMaxPerRow()
and create homogeneously typed rows, meaning they will not have mixed component types.Example
List<ItemComponent> components = Arrays.asList( Button.primary("id1", "Hello"), Button.secondary("id2", "World"), SelectMenu.create("menu:id").build() ); List<ActionRow> partitioned = ActionRow.partition(components); // partitioned[0] = ActionRow(button, button) // partitioned[1] = ActionRow(selectMenu)
- Parameters:
components
- The components to partition- Returns:
List
ofActionRow
- Throws:
IllegalArgumentException
- If null is provided
-
partitionOf
@Nonnull public static List<ActionRow> partitionOf(@Nonnull ItemComponent... components)
Partitions the providedcomponents
into a list of ActionRow instances.
This will split the provided components byComponent.Type.getMaxPerRow()
and create homogeneously typed rows, meaning they will not have mixed component types.Example
List<ItemComponent> components = Arrays.asList( Button.primary("id1", "Hello"), Button.secondary("id2", "World"), SelectMenu.create("menu:id").build() ); List<ActionRow> partitioned = ActionRow.partition(components); // partitioned[0] = ActionRow(button, button) // partitioned[1] = ActionRow(selectMenu)
- Parameters:
components
- The components to partition- Returns:
List
ofActionRow
- Throws:
IllegalArgumentException
- If null is provided
-
getComponents
@Nonnull public List<ItemComponent> getComponents()
Mutable list of components in this ActionRow.
ActionRows should not be empty and are limited to 5 buttons.- Specified by:
getComponents
in interfaceLayoutComponent
- Returns:
- The list of components
-
withDisabled
@Nonnull @CheckReturnValue public ActionRow withDisabled(boolean disabled)
Description copied from interface:LayoutComponent
Returns a new instance of this LayoutComponent with all components set to disabled/enabled.
This does not modify the layout this was called on. To do this in-place, you can useLayoutComponent.getComponents()
.- Specified by:
withDisabled
in interfaceLayoutComponent
- Parameters:
disabled
- True if the components should be set to disabled, false if they should be enabled- Returns:
- The new layout component with all components updated
- See Also:
ActionComponent.withDisabled(boolean)
-
asDisabled
@Nonnull @CheckReturnValue public ActionRow asDisabled()
Description copied from interface:LayoutComponent
Returns a new instance of this LayoutComponent with all components set to disabled.
This does not modify the layout this was called on. To do this in-place, you can useLayoutComponent.getComponents()
.- Specified by:
asDisabled
in interfaceLayoutComponent
- Returns:
- The new layout component with all components updated
- See Also:
ActionComponent.asDisabled()
-
asEnabled
@Nonnull @CheckReturnValue public ActionRow asEnabled()
Description copied from interface:LayoutComponent
Returns a new instance of this LayoutComponent with all components set to enabled.
This does not modify the layout this was called on. To do this in-place, you can useLayoutComponent.getComponents()
.- Specified by:
asEnabled
in interfaceLayoutComponent
- Returns:
- The new layout component with all components updated
- See Also:
ActionComponent.asEnabled()
-
getType
@Nonnull public Component.Type getType()
Description copied from interface:Component
The type of component.- Specified by:
getType
in interfaceComponent
- Returns:
Component.Type
-
toData
@Nonnull public DataObject toData()
Description copied from interface:SerializableData
SerializedDataObject
for this object.- Specified by:
toData
in interfaceSerializableData
- Returns:
DataObject
-
iterator
@Nonnull public Iterator<ItemComponent> iterator()
- Specified by:
iterator
in interfaceIterable<ItemComponent>
-
-