0

我使用下面的代码来组合两个画布。

public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Canvas Test");

Composite mainComp = new Composite(shell, SWT.NONE);
GridLayout layout = new GridLayout(2, false);

layout.horizontalSpacing = 0;

mainComp.setLayout(layout);
mainComp.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, true));

final Canvas hwCanvas = new Canvas(mainComp, SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL);
hwCanvas.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
hwCanvas.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
hwCanvas.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, false, true));
hwCanvas.getVerticalBar().setVisible(false);

final Canvas traceCanvas = new Canvas(mainComp, SWT.NO_REDRAW_RESIZE | SWT.H_SCROLL | SWT.V_SCROLL);
traceCanvas.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
traceCanvas.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
traceCanvas.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, true));

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

}

是否可以增加水平滚动条的宽度(长度),如此处所示 快照

4

1 回答 1

0

尝试将滚动条移动到包含两个画布组件的组件上,这样您的水平滚动条就可以控制它们的总宽度:

Composite mainComp = new Composite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
:
final Canvas hwCanvas = new Canvas(mainComp, SWT.NO_REDRAW_RESIZE);
:
final Canvas traceCanvas = new Canvas(mainComp, SWT.NO_REDRAW_RESIZE);
于 2013-02-05T15:41:00.787 回答