简体   繁体   English

Java / SWT Interface Builder /如何将图像设置为标签

[英]Java / SWT Interface Builder / How to set image to label

I want to set an image into my application. 我想将图像设置到我的应用程序中。 I have created an label within the swt interface builder and set the property "image" to my image (within the src folder). 我已经在swt界面构建器中创建了一个标签,并将属性“ image”设置为我的图像(在src文件夹中)。 The preview displays the correct image. 预览显示正确的图像。

在此处输入图片说明

The code, generated by the interface builder is: 接口构建器生成的代码是:

    lblTest = new Label(shell, SWT.NONE);
    lblTest.setImage(SWTResourceManager.getImage("C:\\Users\\dseek\\Desktop\\PanetHomeProxySwitch\\PlanetHomeProxySwitch\\src\\PH_group_RGB.png"));
    lblTest.setBounds(10, 10, 414, 207);
    lblTest.setText("test");

Yet there is no image (but the label-text displayed) within the app. 但是,应用程序内没有图像(但显示的是标签文本)。

在此处输入图片说明

What am I missing? 我想念什么? Help is very appreciated. 非常感谢您的帮助。

EDIT: 编辑:

If I delete the text property, there is neither an image, nor the text label. 如果删除text属性,则没有图像,也没有文本标签。 This is the preview: 这是预览:

在此处输入图片说明

You source image has the dimensions 3012x1010, but you're restricting the size of the label to 414x207, so you can only actually see the top left corner, which appears to be transparent (or gray). 您的原始图片的尺寸为3012x1010,但是您将标签的尺寸限制为414x207,因此您只能实际看到左上角,它看起来是透明的(或灰色的)。

Note that the Label doesn't automatically rescale the image to fit. 请注意, Label不会自动重新缩放图像以适应尺寸。 This will have to be done manually. 这将必须手动完成。

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

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