2013-10-21 95 views
4

我在我的父級Composite上使用了一個GridLayout,並且想要殺死在渲染對象時創建的1px填充。要改變這部分工作的參數是什麼?我的組合呈現這樣Java SWT Composite 1 px padding

final Composite note = new Composite(parent,SWT.BORDER); 
GridLayout mainLayout = new GridLayout(1,true); 
mainLayout.marginWidth = 0; 
mainLayout.marginHeight = 0; 
mainLayout.verticalSpacing = 0; 
mainLayout.horizontalSpacing = 0; 
note.setLayout(mainLayout); 

圖片:

enter image description here

+0

你說什麼部位? – 2013-10-21 15:02:20

+1

在灰色邊框和藍色框之間,有一條很薄的1px白色線條。不知何故,我想刪除它。 – Johnny000

+1

這是由'SWT.BORDER'造成的。使用'SWT.NONE'來擺脫填充。 – Baz

回答

7

SWT.BORDER導致您的問題。在Windows 7上,它將繪製2px,一個灰色和一個白色的邊框。使用SWT.NONE來完全擺脫邊界。

如果你真的想要一個1px的灰色邊框,可以爲SWT.Paint添加ListenerComposite的父母並使其繪製的GC邊框:

public static void main(String[] args) 
{ 
    final Display display = new Display(); 
    Shell shell = new Shell(display); 
    shell.setLayout(new GridLayout(1, false)); 

    final Composite outer = new Composite(shell, SWT.NONE); 
    outer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 
    GridLayout layout = new GridLayout(1, false); 
    layout.marginHeight = 0; 
    layout.marginWidth = 0; 
    outer.setLayout(layout); 

    Composite inner = new Composite(outer, SWT.NONE); 
    inner.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); 
    inner.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 

    shell.addListener(SWT.Paint, new Listener() 
    { 
     public void handleEvent(Event e) 
     { 
      e.gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BORDER)); 
      Rectangle rect = outer.getBounds(); 
      Rectangle rect1 = new Rectangle(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2); 
      e.gc.setLineStyle(SWT.LINE_SOLID); 
      e.gc.fillRectangle(rect1); 
     } 
    }); 

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

是這樣的:

enter image description here

這裏與綠色背景:

enter image description here