TITLE:Cursorオブジェクトの生成

Usage: #tags(tags)
Posted by at 2005-01-24

Cursorオブジェクトの生成

新しいカスタムカーソルオブジェクトを作成します。

  • &jnlp;
  • &jar;
  • &zip;
CustomCursor.png

サンプルコード

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));
View in GitHub: Java, Kotlin

解説

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

コメント