Class LayoutStyle
java.lang.Object
javax.swing.LayoutStyle
LayoutStyle provides information about how to position
components. This class is primarily useful for visual tools and
layout managers. Most developers will not need to use this class.
You typically don't set or create a
LayoutStyle. Instead use the static method
getInstance to obtain the current instance.
- Since:
- 1.6
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumComponentPlacementis an enumeration of the possible ways two components can be placed relative to each other. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intgetContainerGap(JComponent component, int position, Container parent) Returns the amount of space to place between the component and specified edge of its parent.static LayoutStyleReturns the shared instance ofLayoutStyle.abstract intgetPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent) Returns the amount of space to use between two components.static voidsetInstance(LayoutStyle style) Sets the shared instance ofLayoutStyle.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
LayoutStyle
public LayoutStyle()Creates a newLayoutStyle. You generally don't create aLayoutStyle. Instead use the methodgetInstanceto obtain the currentLayoutStyle.
-
-
Method Details
-
setInstance
Sets the shared instance ofLayoutStyle. Specifyingnullresults in using theLayoutStylefrom the currentLookAndFeel.- Parameters:
style- theLayoutStyle, ornull- See Also:
-
getInstance
Returns the shared instance ofLayoutStyle. If an instance has not been specified insetInstance, this will return theLayoutStylefrom the currentLookAndFeel.- Returns:
- the shared instance of
LayoutStyle - See Also:
-
getPreferredGap
public abstract int getPreferredGap(JComponent component1, JComponent component2, LayoutStyle.ComponentPlacement type, int position, Container parent) Returns the amount of space to use between two components. The return value indicates the distance to placecomponent2relative tocomponent1. For example, the following returns the amount of space to place betweencomponent2andcomponent1whencomponent2is placed vertically abovecomponent1:int gap = getPreferredGap(component1, component2, ComponentPlacement.RELATED, SwingConstants.NORTH, parent);Thetypeparameter indicates the relation between the two components. If the two components will be contained in the same parent and are showing similar logically related items, useRELATED. If the two components will be contained in the same parent but show logically unrelated items useUNRELATED. Some look and feels may not distinguish between theRELATEDandUNRELATEDtypes.The return value is not intended to take into account the current size and position of
component2orcomponent1. The return value may take into consideration various properties of the components. For example, the space may vary based on font size, or the preferred size of the component.- Parameters:
component1- theJComponentcomponent2is being placed relative tocomponent2- theJComponentbeing placedtype- how the two components are being placedposition- the positioncomponent2is being placed relative tocomponent1; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WESTparent- the parent ofcomponent2; this may differ from the actual parent and it may benull- Returns:
- the amount of space to place between the two components
- Throws:
NullPointerException- ifcomponent1,component2ortypeisnullIllegalArgumentException- ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST- Since:
- 1.6
- See Also:
-
getContainerGap
Returns the amount of space to place between the component and specified edge of its parent.- Parameters:
component- theJComponentbeing positionedposition- the positioncomponentis being placed relative to its parent; one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WESTparent- the parent ofcomponent; this may differ from the actual parent and may benull- Returns:
- the amount of space to place between the component and specified edge
- Throws:
IllegalArgumentException- ifpositionis not one ofSwingConstants.NORTH,SwingConstants.SOUTH,SwingConstants.EASTorSwingConstants.WEST
-