我正在尝试在带有绘制图像的画布上使用SWT Scale Component(滑块thingy),缩放用于在画布上放大和缩小,所以我希望标尺周围的灰色区域继承从画布后面绘制的图像,我不能,我已经尝试了here的建议,但似乎继承了背景颜色,但仍然围绕它绘制正方形而不是在该空间上绘制任何东西。
以下是此问题示例中的屏幕截图:
此代码生成上述窗口:
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Shell;
public class ScaleExample extends Canvas{
public ScaleExample(Composite parent, int style) {
super(parent, style);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
ScaleExample.this.paintControl(e);
}
});
this.setBackgroundMode(SWT.INHERIT_FORCE);
Scale zoomRule = new Scale(this, SWT.VERTICAL);
zoomRule.setMinimum(1);
zoomRule.setMaximum(18);
zoomRule.setIncrement(1);
Point p = zoomRule.computeSize(40, 200);
zoomRule.setBounds(10, 10, p.x, p.y);
}
protected void paintControl(PaintEvent e) {
GC gc = e.gc;
Point size = getSize();
int width = size.x, height = size.y;
gc.drawOval(0, 0, width, height);
}
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Scale Example");
shell.setSize(new Point(300, 300));
GridLayout layout = new GridLayout(1, true);
shell.setLayout(layout);
ScaleExample se = new ScaleExample(shell, SWT.BORDER);
se.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}