#navi(../)
*JPanelの背景に画像を並べる [#be947c3e]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2004-09-13~
更新日:&lastmod;

#contents
**概要 [#b30d9291]
JPanelの背景に画像をタイル状に並べて表示します。

http://terai.xrea.jp/swing/backgroundimage/screenshot.png

**サンプルコード [#t9b8baf0]
 public void paintComponent(Graphics g) {
   Dimension d = getSize();
   int w = bgimage.getIconWidth();
   int h = bgimage.getIconHeight();
   for(int i=0;i*w<d.width;i++) {
     for(int j=0;j*h<d.height;j++) {
       g.drawImage(bgimage.getImage(), i*w, j*h, w, h, null);
     }
   }
   //setOpaque(false);
   super.paintComponent(g);
 }

-[[サンプルを起動>http://terai.xrea.jp/swing/backgroundimage/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/backgroundimage/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/backgroundimage/src.zip]]

**解説 [#s57f4112]
このサンプルでは、単純に画像を順番に並べて描画しています。コンポーネントの背景色を透明にしてから、super.paintComponent(g)する必要があります。
**参考リンク [#w44c5faa]
-[[TexturePaintを使って背景に画像を表示>Swing/TexturePaint]]
**コメント [#f9db4b8d]
#comment