Interface ComponentLayout
-
- All Superinterfaces:
java.lang.Iterable<Component>
,SerializableData
- All Known Implementing Classes:
ActionRow
public interface ComponentLayout extends SerializableData, java.lang.Iterable<Component>
Represents a top-level layout used forComponents
such asButtons
.Components must always be contained within such a layout.
- See Also:
ActionRow
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ComponentLayout.Type
The layout types
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.List<Button>
getButtons()
List of buttons in this component layout.java.util.List<Component>
getComponents()
List representation of this component layout.ComponentLayout.Type
getType()
TheComponentLayout.Type
of layoutdefault boolean
isEmpty()
Check whether this layout is empty.default boolean
isValid()
Check whether this is a valid layout configuration.default Component
updateComponent(java.lang.String id, Component newComponent)
Find and replace a component in this layout.static boolean
updateComponent(java.util.List<? extends ComponentLayout> layouts, java.lang.String id, Component newComponent)
Find and replace a component in this list of layouts.-
Methods inherited from interface net.dv8tion.jda.api.utils.data.SerializableData
toData
-
-
-
-
Method Detail
-
getComponents
@Nonnull java.util.List<Component> 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
@Nonnull java.util.List<Button> getButtons()
List of buttons in this component layout.- Returns:
- Immutable
List
ofButtons
-
getType
@Nonnull ComponentLayout.Type getType()
TheComponentLayout.Type
of layout- Returns:
- The layout
ComponentLayout.Type
orComponentLayout.Type.UNKNOWN
-
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 violateComponent.getMaxPerRow()
.- Returns:
- True, if this layout is valid
-
updateComponent
@Nullable default Component updateComponent(@Nonnull java.lang.String id, @Nullable Component 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
Component
that was replaced or removed - Throws:
java.lang.IllegalArgumentException
- If the provided id is null
-
updateComponent
static boolean updateComponent(@Nonnull java.util.List<? extends ComponentLayout> layouts, @Nonnull java.lang.String id, @Nullable Component 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:
java.lang.UnsupportedOperationException
- If the list cannot be modifiedjava.lang.IllegalArgumentException
- If the provided id or list is null or the replace operation results in aninvalid
layout
-
-