1

我想将图像添加到最小值和最大值。

扫描仪将有两个图标 + 和 - 以及 - 区域中的文本和加号区域中的文本的想法

例如缩小(- 图标)......放大(+ 图标)

如何添加图像?

 final Scale scale = new Scale (fComposite, SWT.BORDER);
    Rectangle clientArea = fComposite.getClientArea ();
    scale.setBounds (clientArea.x, clientArea.y, 200, 64);
    scale.setMaximum (4);
    scale.setPageIncrement (1);
    scale.setSelection(4);


    scale.addListener(SWT.Selection, new Listener() {
          public void handleEvent(Event event) {
    .....
          }
        });

谢谢

4

1 回答 1

1

SWT 不支持此功能。

但是,您可以只在 的两侧放置一个Label/CLabel和一个:ImageScale

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

    Composite scaleComp = new Composite(shell, SWT.NONE);
    scaleComp.setLayout(new GridLayout(3, false));

    CLabel leftImage = new CLabel(scaleComp, SWT.RIGHT_TO_LEFT);
    leftImage.setText("Left");
    leftImage.setImage(display.getSystemImage(SWT.ICON_ERROR));
    leftImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));

    final Scale scale = new Scale (scaleComp, SWT.NONE);
    scale.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    scale.setMaximum (4);
    scale.setPageIncrement (1);
    scale.setSelection(4);

    CLabel rightImage = new CLabel(scaleComp, SWT.NONE);
    rightImage.setText("Right");
    rightImage.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    rightImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));

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

看起来像这样:

在此处输入图像描述

于 2013-05-08T10:40:06.887 回答