Interface LayoutComponent
- All Superinterfaces:
Component
,Iterable<ItemComponent>
,SerializableData
- All Known Implementing Classes:
ActionRow
Represents a top-level layout used for
ItemComponents
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 TypeMethodDescriptionReturns a new instance of this LayoutComponent with all components set to disabled.Returns a new instance of this LayoutComponent with all components set to enabled.Creates a copy of thisLayoutComponent
.default @Unmodifiable List
<ActionComponent> Immutable filtered copy ofgetComponents()
elements which areActionComponents
.List of buttons in this component layout.List representation of this component layout.default boolean
Whether all components in this layout aredisabled
.default boolean
isEmpty()
Check whether this layout is empty.default boolean
Whether all components in this layout areenabled
.default boolean
Whether this Component is compatible withMessages
.default boolean
Whether this Component is compatible withModals
.default boolean
isValid()
Check whether this is a valid layout configuration.default ItemComponent
updateComponent
(String id, ItemComponent newComponent) Find and replace a component in this layout.static boolean
updateComponent
(List<? extends LayoutComponent> layouts, String id, ItemComponent newComponent) Find and replace a component in this list of layouts.static boolean
updateComponent
(List<? extends LayoutComponent> layouts, ItemComponent component, ItemComponent newComponent) Find and replace a component in this list of layouts.default ItemComponent
updateComponent
(ItemComponent component, ItemComponent newComponent) Find and replace a component in this layout.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, 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 layouts are not supported.- Returns:
List
of components in this layout
-
isMessageCompatible
default boolean isMessageCompatible()Description copied from interface:Component
Whether this Component is compatible withMessages
.
If the component in question is aLayoutComponent
, this also checks every component inside it.- Specified by:
isMessageCompatible
in interfaceComponent
- Returns:
- True, if this Component is compatible with messages.
-
isModalCompatible
default boolean isModalCompatible()Description copied from interface:Component
Whether this Component is compatible withModals
.
If the component in question is aLayoutComponent
, this also checks every component inside it.- Specified by:
isModalCompatible
in interfaceComponent
- Returns:
- True, if this Component is compatible with modals.
-
getActionComponents
Immutable filtered copy ofgetComponents()
elements which areActionComponents
.- Returns:
- Immutable
List
copy ofActionComponents
in this layout
-
getButtons
List of buttons in this component layout. -
isDisabled
default boolean isDisabled()Whether all components in this layout aredisabled
.
Note that this is a universal quantifier, which means false does not implyisEnabled()
!- Returns:
- True, if all components are disabled
-
isEnabled
default boolean isEnabled()Whether all components in this layout areenabled
.
Note that this is a universal quantifier, which means false does not implyisDisabled()
!- Returns:
- True, if all components are enabled
-
withDisabled
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 usegetComponents()
.- 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:
-
asDisabled
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 usegetComponents()
.- Returns:
- The new layout component with all components updated
- See Also:
-
asEnabled
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 usegetComponents()
.- Returns:
- The new layout component with all components updated
- See Also:
-
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 violateItemComponent.getMaxPerRow()
.- Returns:
- True, if this layout is valid
-
createCopy
Creates a copy of thisLayoutComponent
.
This does not create copies of the contained components.- Returns:
- A copy of this
LayoutComponent
-
updateComponent
@Nullable default ItemComponent updateComponent(@Nonnull String id, @Nullable ItemComponent 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
, or an SKU id forButtonStyle.PREMIUM
newComponent
- The new component or null to remove it- Returns:
- The old
ItemComponent
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 ItemComponent 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
-
updateComponent
@Nullable default ItemComponent updateComponent(@Nonnull ItemComponent component, @Nullable ItemComponent newComponent) Find and replace a component in this layout.
This will locate and replace the existing component by checking forequality
. If you provide null it will be removed instead.Example
public void disableButton(ActionRow row, Button button) { row.updateComponent(button, button.asDisabled()); }
- Parameters:
component
- The component that should be replacednewComponent
- The new component or null to remove it- Returns:
- The old
ItemComponent
that was replaced or removed - Throws:
IllegalArgumentException
- If the provided component is null
-
updateComponent
static boolean updateComponent(@Nonnull List<? extends LayoutComponent> layouts, @Nonnull ItemComponent component, @Nullable ItemComponent newComponent) Find and replace a component in this list of layouts.
This will locate and replace the existing component by checking forequality
. 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 modifycomponent
- The component that should be replacednewComponent
- 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 component or list is null or the replace operation results in aninvalid
layout
-