2011-08-08 50 views
2

我想畫上邊框上的複合材料的這樣的代碼:
SWT:控件邊框的顏色是什麼?

final Composite c = new Composite(parent, SWT.NONE); 
     c.setLayout(new FormLayout()); 
     c.addPaintListener(new PaintListener(){ 

      @Override 
      public void paintControl(PaintEvent e) { 
       int x = c.getBounds().x; 
       int y = c.getBounds().y; 
       e.gc.setForeground(SWTResourceManager.getColor(0)); 
       e.gc.drawLine(x, y-23, x + c.getBounds().width, y-23); 
      } 

     }); 

,但我怎樣才能使邊界問題相同的外觀&感覺作爲默認的邊界?以及如何獲得複合材料的正確Y座標?

我想複合材料只有頂部邊框,有沒有其他方法可以這樣做?

回答

1

1)

您可以爲此使用3個複合材料。 1其中2個放置其中的複合材料。

像:

MainComposite

  • TopComposite(這是邊界和非常小的)
  • CenterComposite(你的信息被放置)

2)

您可以使用Spatial爲內部複合材料使用LayoutData ng信息。但是,你會看到頂部和底部的父組合。

看看

  • GridData.verticalIndent
  • GridData.heightHint
1

這是一個不平凡的問題:-)

看一看在Eclipse UIForms - 特別是org.eclipse.ui.forms.widgets.FormToolkit.BorderPainter ...

1

檢查Detect system settings snippet ,這表明,你怎麼能得到系統顏色。

在你的情況

Color borderColor = display.getSystemColor(SWT.COLOR_WIDGET_BORDER); 
+0

SWT.COLOR_WIDGET_NORMAL_SHADOW將會使邊框看起來像默認。 – CaiNiaoCoder