Top Description Fields Constructors Methods
org.eclipse.swt.graphics

public final Class Rectangle

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.*, org.eclipse.swt.*

Instances of this class represent rectangular areas in an (x, y) coordinate system. The top left corner of the rectangle is specified by its x and y values, and the extent of the rectangle is specified by its width and height.

The coordinate space for rectangles and points is considered to have increasing values downward and to the right from its origin making this the normal, computer graphics oriented notion of (x, y) coordinates rather than the strict mathematical one.

The hashCode() method in this class uses the values of the public fields to compute the hash value. When storing instances of the class in hashed collections, do not modify these fields after the object has been inserted.

Application code does not need to explicitly release the resources managed by each instance when those instances are no longer required, and thus no dispose() method is provided.

See Also
Point, Sample code and further information

Field Summary

Modifier and TypeField and Description
public int
height

the height of the rectangle

pack-priv static final long
public int
width

the width of the rectangle

public int
x

the x coordinate of the rectangle

public int
y

the y coordinate of the rectangle

Constructor Summary

AccessConstructor and Description
public
Rectangle(int
the x coordinate of the origin of the rectangle
x
,
int
the y coordinate of the origin of the rectangle
y
,
int
the width of the rectangle
width
,
int
the height of the rectangle
height
)

Construct a new instance of this class given the x, y, width and height values.

Method Summary

Modifier and TypeMethod and Description
public void
add(Rectangle
the rectangle to merge with the receiver
rect
)

Destructively replaces the x, y, width and height values in the receiver with ones which represent the union of the rectangles specified by the receiver and the given rectangle.

public boolean

Returns:

true if the rectangle contains the point and false otherwise
contains
(int
the x coordinate of the point to test for containment
x
,
int
the y coordinate of the point to test for containment
y
)

Returns true if the point specified by the arguments is inside the area specified by the receiver, and false otherwise.

public boolean

Returns:

true if the rectangle contains the point and false otherwise
contains
(Point
the point to test for containment
pt
)

Returns true if the given point is inside the area specified by the receiver, and false otherwise.

public boolean

Returns:

true if the object is the same as this object and false otherwise
equals
(Object
the object to compare with this object
object
)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.
public int

Returns:

the receiver's hash
hashCode
()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver.
public void
intersect(Rectangle
the rectangle to intersect with the receiver
rect
)

Destructively replaces the x, y, width and height values in the receiver with ones which represent the intersection of the rectangles specified by the receiver and the given rectangle.

public Rectangle

Returns:

the intersection of the receiver and the argument
intersection
(Rectangle
the rectangle to intersect with the receiver
rect
)

Returns a new rectangle which represents the intersection of the receiver and the given rectangle.

public boolean

Returns:

true if the rectangle intersects with the receiver, and false otherwise
intersects
(int
the x coordinate of the origin of the rectangle
x
,
int
the y coordinate of the origin of the rectangle
y
,
int
the width of the rectangle
width
,
int
the height of the rectangle
height
)

Returns true if the rectangle described by the arguments intersects with the receiver and false otherwise.

public boolean

Returns:

true if the rectangle intersects with the receiver, and false otherwise
intersects
(Rectangle
the rectangle to test for intersection
rect
)

Returns true if the given rectangle intersects with the receiver and false otherwise.

public boolean

Returns:

true if the receiver is empty, and false otherwise
isEmpty
()

Returns true if the receiver does not cover any area in the (x, y) coordinate plane, and false if the receiver does cover some area in the plane.

public String

Returns:

a string representation of the rectangle
toString
()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.
public Rectangle

Returns:

the union of the receiver and the argument
union
(Rectangle
the rectangle to perform union with
rect
)

Returns a new rectangle which represents the union of the receiver and the given rectangle.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

heightback to summary
public int height

the height of the rectangle

serialVersionUIDback to summary
pack-priv static final long serialVersionUID
widthback to summary
public int width

the width of the rectangle

xback to summary
public int x

the x coordinate of the rectangle

yback to summary
public int y

the y coordinate of the rectangle

Constructor Detail

Rectangleback to summary
public Rectangle(int x, int y, int width, int height)

Construct a new instance of this class given the x, y, width and height values.

Parameters
x:int

the x coordinate of the origin of the rectangle

y:int

the y coordinate of the origin of the rectangle

width:int

the width of the rectangle

height:int

the height of the rectangle

Method Detail

addback to summary
public void add(Rectangle rect)

Destructively replaces the x, y, width and height values in the receiver with ones which represent the union of the rectangles specified by the receiver and the given rectangle.

The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.

Parameters
rect:Rectangle

the rectangle to merge with the receiver

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
containsback to summary
public boolean contains(int x, int y)

Returns true if the point specified by the arguments is inside the area specified by the receiver, and false otherwise.

Parameters
x:int

the x coordinate of the point to test for containment

y:int

the y coordinate of the point to test for containment

Returns:boolean

true if the rectangle contains the point and false otherwise

containsback to summary
public boolean contains(Point pt)

Returns true if the given point is inside the area specified by the receiver, and false otherwise.

Parameters
pt:Point

the point to test for containment

Returns:boolean

true if the rectangle contains the point and false otherwise

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.

Parameters
object:Object

the object to compare with this object

Returns:boolean

true if the object is the same as this object and false otherwise

Annotations
@Override
See Also
hashCode()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns an integer hash code for the receiver. Any two objects that return true when passed to equals must return the same value for this method.

Returns:int

the receiver's hash

Annotations
@Override
See Also
equals(Object)
intersectback to summary
public void intersect(Rectangle rect)

Destructively replaces the x, y, width and height values in the receiver with ones which represent the intersection of the rectangles specified by the receiver and the given rectangle.

Parameters
rect:Rectangle

the rectangle to intersect with the receiver

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
since 3.0
intersectionback to summary
public Rectangle intersection(Rectangle rect)

Returns a new rectangle which represents the intersection of the receiver and the given rectangle.

The intersection of two rectangles is the rectangle that covers the area which is contained within both rectangles.

Parameters
rect:Rectangle

the rectangle to intersect with the receiver

Returns:Rectangle

the intersection of the receiver and the argument

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
intersectsback to summary
public boolean intersects(int x, int y, int width, int height)

Returns true if the rectangle described by the arguments intersects with the receiver and false otherwise.

Two rectangles intersect if the area of the rectangle representing their intersection is not empty.

Parameters
x:int

the x coordinate of the origin of the rectangle

y:int

the y coordinate of the origin of the rectangle

width:int

the width of the rectangle

height:int

the height of the rectangle

Returns:boolean

true if the rectangle intersects with the receiver, and false otherwise

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
Since
3.0
See Also
intersection(Rectangle), isEmpty()
intersectsback to summary
public boolean intersects(Rectangle rect)

Returns true if the given rectangle intersects with the receiver and false otherwise.

Two rectangles intersect if the area of the rectangle representing their intersection is not empty.

Parameters
rect:Rectangle

the rectangle to test for intersection

Returns:boolean

true if the rectangle intersects with the receiver, and false otherwise

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
See Also
intersection(Rectangle), isEmpty()
isEmptyback to summary
public boolean isEmpty()

Returns true if the receiver does not cover any area in the (x, y) coordinate plane, and false if the receiver does cover some area in the plane.

A rectangle is considered to cover area in the (x, y) coordinate plane if both its width and height are non-zero.

Returns:boolean

true if the receiver is empty, and false otherwise

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string containing a concise, human-readable description of the receiver.

Returns:String

a string representation of the rectangle

Annotations
@Override
unionback to summary
public Rectangle union(Rectangle rect)

Returns a new rectangle which represents the union of the receiver and the given rectangle.

The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.

Parameters
rect:Rectangle

the rectangle to perform union with

Returns:Rectangle

the union of the receiver and the argument

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the argument is null
See Also
add(Rectangle)