APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class Dimension

extends Dimension2D
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
javax.swing.plaf.DimensionUIResource
Imports
java.awt.geom.Dimension2D, java.beans.Transient, java.io.Serial

The Dimension class encapsulates the width and height of a component (in integer precision) in a single object. The class is associated with certain properties of components. Several methods defined by the Component class and the LayoutManager interface return a Dimension object.

Normally the values of width and height are non-negative integers. The constructors that allow you to create a dimension do not prevent you from setting a negative value for these properties. If the value of width or height is negative, the behavior of some methods defined by other objects is undefined.

Authors
Sami Shaio, Arthur van Hoff
Since
1.0
See Also
java.awt.Component, java.awt.LayoutManager

Field Summary

Modifier and TypeField and Description
public int
height

The height dimension; negative values can be used.

private static final long
serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

public int
width

The width dimension; negative values can be used.

Constructor Summary

AccessConstructor and Description
public
Dimension()

Creates an instance of Dimension with a width of zero and a height of zero.

public
Dimension(Dimension
the specified dimension for the width and height values
d
)

Creates an instance of Dimension whose width and height are the same as for the specified dimension.

public
Dimension(int
the specified width
width
,
int
the specified height
height
)

Constructs a Dimension and initializes it to the specified width and specified height.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Checks whether two dimension objects have equal values.

public double
getHeight()

Implements abstract java.awt.geom.Dimension2D.getHeight.

Returns the height of this Dimension in double precision.

public Dimension

Returns:

the size of this dimension, a new instance of Dimension with the same width and height
getSize
()

Gets the size of this Dimension object.

public double
getWidth()

Implements abstract java.awt.geom.Dimension2D.getWidth.

Returns the width of this Dimension in double precision.

public int

Returns:

a hash code for this Dimension
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code for this Dimension.

private static native void
initIDs()

Initialize JNI field and method IDs

public void
setSize(double
the new width for the Dimension object
width
,
double
the new height for the Dimension object
height
)

Implements abstract java.awt.geom.Dimension2D.setSize.

Sets the size of this Dimension object to the specified width and height in double precision.

public void
setSize(Dimension
the new size for this Dimension object
d
)

Sets the size of this Dimension object to the specified size.

public void
setSize(int
the new width for this Dimension object
width
,
int
the new height for this Dimension object
height
)

Sets the size of this Dimension object to the specified width and height.

public String

Returns:

a string representation of this Dimension object
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the values of this Dimension object's height and width fields.

Inherited from java.awt.geom.Dimension2D:
clonesetSize

Field Detail

heightback to summary
public int height

The height dimension; negative values can be used.

Since
1.0
See Also
getSize, setSize
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
widthback to summary
public int width

The width dimension; negative values can be used.

Since
1.0
See Also
getSize, setSize

Constructor Detail

Dimensionback to summary
public Dimension()

Creates an instance of Dimension with a width of zero and a height of zero.

Dimensionback to summary
public Dimension(Dimension d)

Creates an instance of Dimension whose width and height are the same as for the specified dimension.

Parameters
d:Dimension

the specified dimension for the width and height values

Dimensionback to summary
public Dimension(int width, int height)

Constructs a Dimension and initializes it to the specified width and specified height.

Parameters
width:int

the specified width

height:int

the specified height

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Checks whether two dimension objects have equal values.

getHeightback to summary
public double getHeight()

Implements abstract java.awt.geom.Dimension2D.getHeight.

Doc from java.awt.geom.Dimension2D.getHeight.

Returns the height of this Dimension in double precision.

Since
1.2
getSizeback to summary
public Dimension getSize()

Gets the size of this Dimension object. This method is included for completeness, to parallel the getSize method defined by Component.

Returns:Dimension

the size of this dimension, a new instance of Dimension with the same width and height

Annotations
@Transient
Since
1.1
See Also
java.awt.Dimension#setSize, java.awt.Component#getSize
getWidthback to summary
public double getWidth()

Implements abstract java.awt.geom.Dimension2D.getWidth.

Doc from java.awt.geom.Dimension2D.getWidth.

Returns the width of this Dimension in double precision.

Since
1.2
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code for this Dimension.

Returns:int

a hash code for this Dimension

initIDsback to summary
private static native void initIDs()

Initialize JNI field and method IDs

setSizeback to summary
public void setSize(double width, double height)

Implements abstract java.awt.geom.Dimension2D.setSize.

Sets the size of this Dimension object to the specified width and height in double precision. Note that if width or height are larger than Integer.MAX_VALUE, they will be reset to Integer.MAX_VALUE.

Parameters
width:double

the new width for the Dimension object

height:double

the new height for the Dimension object

Since
1.2
setSizeback to summary
public void setSize(Dimension d)

Sets the size of this Dimension object to the specified size. This method is included for completeness, to parallel the setSize method defined by Component.

Parameters
d:Dimension

the new size for this Dimension object

Since
1.1
See Also
java.awt.Dimension#getSize, java.awt.Component#setSize
setSizeback to summary
public void setSize(int width, int height)

Sets the size of this Dimension object to the specified width and height. This method is included for completeness, to parallel the setSize method defined by Component.

Parameters
width:int

the new width for this Dimension object

height:int

the new height for this Dimension object

Since
1.1
See Also
java.awt.Dimension#getSize, java.awt.Component#setSize
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the values of this Dimension object's height and width fields. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns:String

a string representation of this Dimension object