我在我的父Composite上使用了一个GridLayout,并希望终止在渲染对象时创建的1px填充.要使此部件工作,要更改的参数是什么?我的复合材料就是这样呈现的
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);
Run Code Online (Sandbox Code Playgroud)
图片:

SWT.BORDER导致你的问题.在Windows 7上,它将绘制2px,一个灰色和一个白色的边框.使用SWT.NONE摆脱边框的完全.
如果你真的想要一个1px灰色边框,你可以为你的父母添加一个Listenerfor SWT.Paint,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();
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:

这里有绿色背景:

| 归档时间: |
|
| 查看次数: |
5724 次 |
| 最近记录: |