SWT.BORDER
導致您的問題。在Windows 7上,它將繪製2px,一個灰色和一個白色的邊框。使用SWT.NONE
來完全擺脫邊界。
如果你真的想要一個1px的灰色邊框,可以爲SWT.Paint
添加Listener
您Composite
的父母並使其繪製的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();
}
是這樣的:

這裏與綠色背景:

來源
2013-10-21 15:41:22
Baz
你說什麼部位? – 2013-10-21 15:02:20
在灰色邊框和藍色框之間,有一條很薄的1px白色線條。不知何故,我想刪除它。 – Johnny000
這是由'SWT.BORDER'造成的。使用'SWT.NONE'來擺脫填充。 – Baz