繁体   English   中英

如何按比例添加图像?

[英]How to add image to scale?

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

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

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

如何添加图像?

 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) {
    .....
          }
        });

谢谢

SWT不支持此功能。

但是,你可以把一个Label / CLabelImage的两侧Scale

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();
}

看起来像这样:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM