---
title: Cursorオブジェクトの生成
tags: [Cursor, BufferedImage, ImageIcon, JComponent]
author: aterai
pubdate: 2005-01-24
description: BufferedImageからカーソルオブジェクトを作成し、これをコンポーネントに設定します。
---
* 概要 [#l60ded0f]
`BufferedImage`からカーソルオブジェクトを作成し、これをコンポーネントに設定します。

#download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKTOEY7FI/AAAAAAAAAVw/OeBJRlIWHsQ/s800/CustomCursor.png)

* サンプルコード [#x837b7d6]
#code(link){{
BufferedImage bi2 = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d2 = bi2.createGraphics();
g2d2.setPaint(Color.RED);
g2d2.drawOval(8, 8, 16, 16);
g2d2.dispose();
lbl2.setCursor(getToolkit().createCustomCursor(bi2, new Point(16, 16), "oval"));
label2.setIcon(new ImageIcon(bi2));
}}

* 解説 [#k25e265f]
`Toolkit#createCustomCursor`メソッドでカーソルオブジェクトを作成します。上記のサンプルコードでは、`32*32`のバッファの中心に、直径`16`の円をかき、この円の中心がホットスポットとなるようなカーソルを作っています。

//* 参考リンク
* コメント [#qecf5901]
#comment
#comment