Package org.eclipse.jface.resource

# Class ColorDescriptor

java.lang.Object
org.eclipse.jface.resource.DeviceResourceDescriptor<Color>
org.eclipse.jface.resource.ColorDescriptor

public abstract class ColorDescriptor extends DeviceResourceDescriptor<Color>
Lightweight descriptor for an SWT color. Each ColorDescriptor will create a particular SWT Color on demand. This object will be compared so hashCode(...) and equals(...) must return meaningful values.

Since:
  3.1

## Constructor Summary

Constructors
Constructor
Description
`ColorDescriptor()`

## Method Summary

Modifier and Type
Method
Description
`abstract Color`
`createColor(Device device)`
Returns the Color described by this descriptor.
`static ColorDescriptor`
`createFrom(Color toCreate)`
Creates a ColorDescriptor from an existing color.
`static ColorDescriptor`
`createFrom(Color toCreate, Device originalDevice)`
Deprecated, for removal: This API element is subject to removal in a future version.
use `createFrom(Color)`
`static ColorDescriptor`
`createFrom(RGB toCreate)`
Returns a color descriptor for the given RGB values
`final Object`
`createResource(Device device)`
Creates the resource described by this descriptor
`void`
`destroyColor(Color toDestroy)`
Deprecated.
Colors do not need disposal anymore
`final void`
`destroyResource(Object previouslyCreatedObject)`
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ColorDescriptor

public ColorDescriptor()

## Method Details

### createFrom

@Deprecated(forRemoval=true, since="2026-03") public static ColorDescriptor createFrom(Color toCreate, Device originalDevice)
Deprecated, for removal: This API element is subject to removal in a future version.
use `createFrom(Color)`
Creates a ColorDescriptor from an existing Color, given the Device associated with the original Color. This is the usual way to convert a Color into a ColorDescriptor. Note that the returned ColorDescriptor depends on the original Color, and disposing the Color will invalidate the ColorDescriptor.

Parameters:
  `toCreate` - Color to convert into a ColorDescriptor.
  `originalDevice` - this must be the same Device that was passed into the original Color's constructor.
Returns:
  a newly created ColorDescriptor that describes the given Color.
Since:
  3.1

### createFrom

public static ColorDescriptor createFrom(Color toCreate)
Creates a ColorDescriptor from an existing color. The returned ColorDescriptor depends on the original Color. Disposing the original colour while the color descriptor is still in use may cause SWT to throw a graphic disposed exception.

Parameters:
  `toCreate` - Color to generate a ColorDescriptor from
Returns:
  a newly created ColorDescriptor
Since:
  3.1

### createFrom

public static ColorDescriptor createFrom(RGB toCreate)
Returns a color descriptor for the given RGB values

Parameters:
  `toCreate` - RGB values to create
Returns:
  a new ColorDescriptor
Since:
  3.1

### createColor

public abstract Color createColor(Device device) throws DeviceResourceException
Returns the Color described by this descriptor.

Parameters:
  `device` - SWT device on which to allocate the Color
Returns:
  a newly allocated SWT Color object (never null)
Throws:
  `DeviceResourceException` - if unable to allocate the Color

### destroyColor

@Deprecated public void destroyColor(Color toDestroy)
Deprecated.
Colors do not need disposal anymore
Undoes whatever was done by createColor.

Parameters:
  `toDestroy` - a Color that was previously allocated by an equal ColorDescriptor
Since:
  3.1

### createResource

public final Object createResource(Device device) throws DeviceResourceException
Description copied from class: `DeviceResourceDescriptor`
Creates the resource described by this descriptor

Specified by:
  `createResource` in class `DeviceResourceDescriptor<Color>`
Parameters:
  `device` - the Device on which to allocate the resource
Returns:
  the newly allocated resource (not null)
Throws:
  `DeviceResourceException` - if unable to allocate the resource

### destroyResource

public final void destroyResource(Object previouslyCreatedObject)
Description copied from class: `DeviceResourceDescriptor`
Undoes everything that was done by a previous call to create(...), given the object that was returned by create(...).

Specified by:
  `destroyResource` in class `DeviceResourceDescriptor<Color>`
Parameters:
  `previouslyCreatedObject` - an object that was returned by an equal descriptor in a previous call to createResource(...).