- java.lang.Object
-
- java.awt.CardLayout
-
- All Implemented Interfaces:
- LayoutManager, LayoutManager2, Serializable
public class CardLayout extends Object implements LayoutManager2, Serializable
ACardLayout
object is a layout manager for a container. It treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to aCardLayout
object is the visible component when the container is first displayed.The ordering of cards is determined by the container's own internal ordering of its component objects.
CardLayout
defines a set of methods that allow an application to flip through these cards sequentially, or to show a specified card. TheaddLayoutComponent(java.awt.Component, java.lang.Object)
method can be used to associate a string identifier with a given card for fast random access.- Since:
- JDK1.0
- See Also:
Container
, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description CardLayout()
Creates a new card layout with gaps of size zero.CardLayout(int hgap, int vgap)
Creates a new card layout with the specified horizontal and vertical gaps.
-
Method Summary
Methods Modifier and Type Method and Description void
addLayoutComponent(Component comp, Object constraints)
Adds the specified component to this card layout's internal table of names.void
addLayoutComponent(String name, Component comp)
Deprecated.replaced byaddLayoutComponent(Component, Object)
.void
first(Container parent)
Flips to the first card of the container.int
getHgap()
Gets the horizontal gap between components.float
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis.float
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis.int
getVgap()
Gets the vertical gap between components.void
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.void
last(Container parent)
Flips to the last card of the container.void
layoutContainer(Container parent)
Lays out the specified container using this card layout.Dimension
maximumLayoutSize(Container target)
Returns the maximum dimensions for this layout given the components in the specified target container.Dimension
minimumLayoutSize(Container parent)
Calculates the minimum size for the specified panel.void
next(Container parent)
Flips to the next card of the specified container.Dimension
preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this card layout.void
previous(Container parent)
Flips to the previous card of the specified container.void
removeLayoutComponent(Component comp)
Removes the specified component from the layout.void
setHgap(int hgap)
Sets the horizontal gap between components.void
setVgap(int vgap)
Sets the vertical gap between components.void
show(Container parent, String name)
Flips to the component that was added to this layout with the specifiedname
, usingaddLayoutComponent
.String
toString()
Returns a string representation of the state of this card layout.
-
-
-
Constructor Detail
-
CardLayout
public CardLayout()
Creates a new card layout with gaps of size zero.
-
CardLayout
public CardLayout(int hgap, int vgap)
Creates a new card layout with the specified horizontal and vertical gaps. The horizontal gaps are placed at the left and right edges. The vertical gaps are placed at the top and bottom edges.- Parameters:
hgap
- the horizontal gap.vgap
- the vertical gap.
-
-
Method Detail
-
getHgap
public int getHgap()
Gets the horizontal gap between components.- Returns:
- the horizontal gap between components.
- Since:
- JDK1.1
- See Also:
setHgap(int)
,getVgap()
-
setHgap
public void setHgap(int hgap)
Sets the horizontal gap between components.- Parameters:
hgap
- the horizontal gap between components.- Since:
- JDK1.1
- See Also:
getHgap()
,setVgap(int)
-
getVgap
public int getVgap()
Gets the vertical gap between components.- Returns:
- the vertical gap between components.
- See Also:
setVgap(int)
,getHgap()
-
setVgap
public void setVgap(int vgap)
Sets the vertical gap between components.- Parameters:
vgap
- the vertical gap between components.- Since:
- JDK1.1
- See Also:
getVgap()
,setHgap(int)
-
addLayoutComponent
public void addLayoutComponent(Component comp, Object constraints)
Adds the specified component to this card layout's internal table of names. The object specified byconstraints
must be a string. The card layout stores this string as a key-value pair that can be used for random access to a particular card. By calling theshow
method, an application can display the component with the specified name.- Specified by:
addLayoutComponent
in interfaceLayoutManager2
- Parameters:
comp
- the component to be added.constraints
- a tag that identifies a particular card in the layout.- Throws:
IllegalArgumentException
- if the constraint is not a string.- See Also:
show(java.awt.Container, java.lang.String)
-
addLayoutComponent
@Deprecated public void addLayoutComponent(String name, Component comp)
Deprecated. replaced byaddLayoutComponent(Component, Object)
.Description copied from interface:LayoutManager
If the layout manager uses a per-component string, adds the componentcomp
to the layout, associating it with the string specified byname
.- Specified by:
addLayoutComponent
in interfaceLayoutManager
- Parameters:
name
- the string to be associated with the componentcomp
- the component to be added
-
removeLayoutComponent
public void removeLayoutComponent(Component comp)
Removes the specified component from the layout. If the card was visible on top, the next card underneath it is shown.- Specified by:
removeLayoutComponent
in interfaceLayoutManager
- Parameters:
comp
- the component to be removed.- See Also:
Container.remove(java.awt.Component)
,Container.removeAll()
-
preferredLayoutSize
public Dimension preferredLayoutSize(Container parent)
Determines the preferred size of the container argument using this card layout.- Specified by:
preferredLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- the parent container in which to do the layout- Returns:
- the preferred dimensions to lay out the subcomponents of the specified container
- See Also:
Container.getPreferredSize()
,minimumLayoutSize(java.awt.Container)
-
minimumLayoutSize
public Dimension minimumLayoutSize(Container parent)
Calculates the minimum size for the specified panel.- Specified by:
minimumLayoutSize
in interfaceLayoutManager
- Parameters:
parent
- the parent container in which to do the layout- Returns:
- the minimum dimensions required to lay out the subcomponents of the specified container
- See Also:
Container.doLayout()
,preferredLayoutSize(java.awt.Container)
-
maximumLayoutSize
public Dimension maximumLayoutSize(Container target)
Returns the maximum dimensions for this layout given the components in the specified target container.- Specified by:
maximumLayoutSize
in interfaceLayoutManager2
- Parameters:
target
- the component which needs to be laid out- See Also:
Container
,minimumLayoutSize(java.awt.Container)
,preferredLayoutSize(java.awt.Container)
-
getLayoutAlignmentX
public float getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentX
in interfaceLayoutManager2
-
getLayoutAlignmentY
public float getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.- Specified by:
getLayoutAlignmentY
in interfaceLayoutManager2
-
invalidateLayout
public void invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.- Specified by:
invalidateLayout
in interfaceLayoutManager2
-
layoutContainer
public void layoutContainer(Container parent)
Lays out the specified container using this card layout.Each component in the
parent
container is reshaped to be the size of the container, minus space for surrounding insets, horizontal gaps, and vertical gaps.- Specified by:
layoutContainer
in interfaceLayoutManager
- Parameters:
parent
- the parent container in which to do the layout- See Also:
Container.doLayout()
-
first
public void first(Container parent)
Flips to the first card of the container.- Parameters:
parent
- the parent container in which to do the layout- See Also:
last(java.awt.Container)
-
next
public void next(Container parent)
Flips to the next card of the specified container. If the currently visible card is the last one, this method flips to the first card in the layout.- Parameters:
parent
- the parent container in which to do the layout- See Also:
previous(java.awt.Container)
-
previous
public void previous(Container parent)
Flips to the previous card of the specified container. If the currently visible card is the first one, this method flips to the last card in the layout.- Parameters:
parent
- the parent container in which to do the layout- See Also:
next(java.awt.Container)
-
last
public void last(Container parent)
Flips to the last card of the container.- Parameters:
parent
- the parent container in which to do the layout- See Also:
first(java.awt.Container)
-
show
public void show(Container parent, String name)
Flips to the component that was added to this layout with the specifiedname
, usingaddLayoutComponent
. If no such component exists, then nothing happens.- Parameters:
parent
- the parent container in which to do the layoutname
- the component name- See Also:
addLayoutComponent(java.awt.Component, java.lang.Object)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-java/awt/CardLayout.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.