2011-11-09 8 views
2

SWTを使用してグラフィカルアプリケーションを作成しています。まず、イメージの背景(shell.setBackgroundImage(image))を持つシェルを作成し、別の背景イメージとコンポジットを入れて、コンポジットを使ってその内部にラベルを配置することができました。問題は、コンポジットの周りの灰色の境界を取り除くことができないことです。まったく行うことは可能ですか、それを行うには他の方法がありますか?ここでSWT Java - イメージバックグラウンドを持つコンポジットをイメージバックグラウンドのシェルに配置する

はコードです:ここでは

import org.eclipse.swt.SWT; 
import org.eclipse.swt.graphics.Image; 
import org.eclipse.swt.widgets.Composite; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Label; 
import org.eclipse.swt.widgets.Shell; 

public class Test { 

    protected static int gap = 20; 

    public static void main (String[] args) { 

     Display display = new Display(); 
     Shell shell = new Shell(display); 
     Image bg_Image = new Image(display, "bg_full.png"); 
     shell.setBackgroundImage(bg_Image); 
     shell.setBackgroundMode(SWT.INHERIT_FORCE); 
     shell.setFullScreen(true); 

     Image bg = new Image(display, "bg.png"); 
     Image border = new Image(display, "bg_info.png"); 
     Image b1 = new Image(display, "button_total_active.png"); 
     Image b2 = new Image(display, "button_terminal.png"); 
     Image b3 = new Image(display, "button_operator.png"); 
     Image b4 = new Image(display, "button_contract.png"); 

     Composite composite = new Composite(shell, SWT.NONE); 
     composite.setBackgroundImage(bg); 
     composite.setBackgroundMode(SWT.INHERIT_FORCE); 
     composite.setBounds(80, 220, bg.getBounds().width, bg.getBounds().height); 

     Label label1 = new Label(composite, SWT.NONE); 
     label1.setImage(b1); 
     label1.setBounds(gap, gap, b1.getBounds().width, b1.getBounds().height); 

     Label label2 = new Label(composite, SWT.NONE); 
     label2.setImage(b2); 
     label2.setBounds(gap, gap*2+b1.getBounds().height, b2.getBounds().width, b2.getBounds().height); 

     Label label3 = new Label(composite, SWT.NONE); 
     label3.setImage(b3); 
     label3.setBounds(gap, gap*3+b1.getBounds().height*2, b3.getBounds().width, b3.getBounds().height); 

     Label label4 = new Label(composite, SWT.NONE); 
     label4.setImage(b4); 
     label4.setBounds(gap, gap*4+b1.getBounds().height*3, b4.getBounds().width, b4.getBounds().height); 

     Label label5 = new Label(composite, SWT.NONE); 
     label5.setImage(border); 
     label5.setBounds(gap*2+b1.getBounds().width, gap, border.getBounds().width, border.getBounds().height); 

     shell.open(); 
     while (!shell.isDisposed()) { 
      if (!display.readAndDispatch()) 
       display.sleep();  
     } 
     display.dispose(); 

    } 
} 

は(あなたがSWT.INHERIT_FORCEによってそれらを取り除く)、これらは透明でない画像の透明のコーナーであるこれらは、灰色の境界ではありませんsample image

答えて

1

ですそれらの背後に複合体があるからです。あなたが知っている限り、コンポジットの背景としてイメージのコーナーを削除することはできません。これらのコーナーが透明で白でない場合は、GCを使用してhereのようにこの画像をシェル上に描画できます(コンポジットを作成せずに)。
透明な画像を配置するときは、後ろに見えるようにするオブジェクトにそれらを配置します。私はあなたを助けてくれたと思う。 :)

+0

Gene Marinは私の質問に答えてくれてありがとう、はい私はこれらの境界線が透明である(おそらく私はそれを明確にしていないかもしれない)ことを知っていて、GCを使った描画にも精通しています)この障害を処理する:私はシェルを作成する(画像の背景を持つ)、私はそれに画像を描画することができますし、この画像の上にラベル(画像あり)を置く必要があります。これを克服して、何か考えがあるかもしれませんか?希望がこのリンク(http://file.karelia.ru/5rrvrv/)私の質問を明確にします。事前に感謝します – foma

+0

私はこの障害を処理するためにスイングを使用していませんそれは完璧に動作します。とにかくありがとう – foma

関連する問題