Interface LayoutComponent
- All Superinterfaces:
Component
,Iterable<ActionComponent>
,SerializableData
- All Known Implementing Classes:
ActionRow
Represents a top-level layout used for
ActionComponents
such as Buttons
.
Components must always be contained within such a layout.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.interactions.components.Component
Component.Type
-
Method Summary
Modifier and TypeMethodDescriptionList of buttons in this component layout.List representation of this component layout.default boolean
isEmpty()
Check whether this layout is empty.default boolean
isValid()
Check whether this is a valid layout configuration.default ActionComponent
updateComponent
(String id, ActionComponent newComponent) Find and replace a component in this layout.static boolean
updateComponent
(List<? extends LayoutComponent> layouts, String id, ActionComponent newComponent) Find and replace a component in this list of layouts.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
Method Details
-
getComponents
List representation of this component layout.
This list is modifiable. Note that empty action rows are not supported.- Returns:
List
of components in this action row
-
getButtons
List of buttons in this component layout. -
isEmpty
default boolean isEmpty()Check whether this layout is empty.
Identical togetComponents().isEmpty()
- Returns:
- True, if this layout has no components
-
isValid
default boolean isValid()Check whether this is a valid layout configuration.
This checks that there is at least one component in this layout and it does not violateActionComponent.getMaxPerRow()
.- Returns:
- True, if this layout is valid
-
updateComponent
@Nullable default ActionComponent updateComponent(@Nonnull String id, @Nullable ActionComponent newComponent) Find and replace a component in this layout.
This will locate and replace the existing component with the specified ID. If you provide null it will be removed instead.- Parameters:
id
- The custom id of this component, can also be a URL for aButton
withButtonStyle.LINK
newComponent
- The new component or null to remove it- Returns:
- The old
ActionComponent
that was replaced or removed - Throws:
IllegalArgumentException
- If the provided id is null
-
updateComponent
static boolean updateComponent(@Nonnull List<? extends LayoutComponent> layouts, @Nonnull String id, @Nullable ActionComponent newComponent) Find and replace a component in this list of layouts.
This will locate and replace the existing component with the specified ID. If you provide null it will be removed instead.If one of the layouts is empty after removing the component, it will be removed from the list. This is an inplace operation and modifies the provided list directly.
- Parameters:
layouts
- The layouts to modifyid
- The custom id of this component, can also be a URL for aButton
withButtonStyle.LINK
newComponent
- The new component or null to remove it- Returns:
- True, if any of the layouts was modified
- Throws:
UnsupportedOperationException
- If the list cannot be modifiedIllegalArgumentException
- If the provided id or list is null or the replace operation results in aninvalid
layout
-