Swing/CustomCursor のバックアップの現在との差分(No.4)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/CustomCursor へ行く。
- 1 (2005-01-23 (日) 18:58:37)
- 2 (2005-01-23 (日) 19:07:56)
- 3 (2005-04-28 (木) 04:33:04)
- 4 (2005-11-02 (水) 21:01:00)
- 5 (2006-01-27 (金) 23:18:53)
- 6 (2006-02-27 (月) 15:36:37)
- 7 (2006-04-01 (土) 03:44:46)
- 8 (2006-04-12 (水) 19:39:32)
- 9 (2006-07-01 (土) 16:54:17)
- 10 (2007-03-26 (月) 00:32:51)
- 11 (2007-10-11 (木) 12:51:47)
- 12 (2009-06-22 (月) 12:29:24)
- 13 (2013-02-26 (火) 19:50:55)
- 14 (2013-03-31 (日) 20:05:22)
- 15 (2014-10-16 (木) 11:47:47)
- 16 (2014-11-27 (木) 17:17:12)
- 17 (2016-01-08 (金) 19:17:57)
- 18 (2016-09-08 (木) 18:01:44)
- 19 (2017-08-15 (火) 14:04:19)
- 20 (2017-08-22 (火) 15:25:24)
- 21 (2018-08-31 (金) 17:42:48)
- 22 (2019-11-28 (木) 15:49:08)
- 23 (2021-06-03 (木) 11:50:37)
- 追加された行はこの色です。
- 削除された行はこの色です。
#navi(../) *Cursorオブジェクトの生成 [#l60ded0f] >編集者:[[Terai Atsuhiro>terai]]~ 作成日:2005-01-24~ 更新日:&lastmod; --- category: swing folder: CustomCursor title: Cursorオブジェクトの生成 tags: [Cursor, BufferedImage, ImageIcon, JComponent] author: aterai pubdate: 2005-01-24T03:58:31+09:00 description: BufferedImageからカーソルオブジェクトを作成し、これをコンポーネントに設定します。 image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKTOEY7FI/AAAAAAAAAVw/OeBJRlIWHsQ/s800/CustomCursor.png --- * 概要 [#summary] `BufferedImage`からカーソルオブジェクトを作成し、これをコンポーネントに設定します。 #contents **概要 [#c4de6873] 新しいカスタムカーソルオブジェクトを作成します。 #download(https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTKTOEY7FI/AAAAAAAAAVw/OeBJRlIWHsQ/s800/CustomCursor.png) //http://terai.xrea.jp/swing/customcursor/screenshot.png * サンプルコード [#sourcecode] #code(link){{ BufferedImage bi = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bi.createGraphics(); g2.setPaint(Color.RED); g2.drawOval(8, 8, 16, 16); g2.dispose(); button.setCursor(getToolkit().createCustomCursor(bi, new Point(16, 16), "oval")); }} **サンプルコード [#x837b7d6] BufferedImage bi2 = new BufferedImage(32, 32, BufferedImage.TYPE_4BYTE_ABGR); 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")); * 解説 [#explanation] - サイズが`32x32px`の`BufferedImage`から`Toolkit#createCustomCursor(...)`メソッドを使用してカーソルオブジェクトを作成 -- ホットスポットはその`BufferedImage`の中心に設定 - `String`: `BufferedImage`に文字を描画 - `drawOval`: `BufferedImage`に円を描画 - `paintIcon`: `BufferedImage`に`Icon`を描画 -[[サンプルを起動>http://terai.xrea.jp/swing/customcursor/sample.jnlp]] -[[jarファイル>http://terai.xrea.jp/swing/customcursor/sample.jar]] -[[ソース>http://terai.xrea.jp/swing/customcursor/src.zip]] * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/Toolkit.html#createCustomCursor-java.awt.Image-java.awt.Point-java.lang.String- Toolkit#createCustomCursor(...) (Java Platform SE 8)] **解説 [#k25e265f] Toolkit#createCustomCursorでカーソルオブジェクトを作成します。上記のサンプルでは、32*32のバッファの中心に、直径16ptの円をかき、中心がカーソルのホットスポットとなるようなカーソルを作っています。 //**参考リンク **コメント [#qecf5901] * コメント [#comment] #comment #comment