Topic: 如何在Label和Button上贴图?

  Print this page

1.如何在Label和Button上贴图? Copy to clipboard
Posted by: zf00110011
Posted on: 2006-05-18 13:44

程序如下:
String strRight = "icons/1.gif";
Image image = new Image(null,strRight);

//photoComp是放置图片Composite 的父Composite
Composite tempComp = new Composite(photoComp,SWT.BORDER);
tempComp.setLayoutData(new GridData(50,50));

//我用Button 和Label 各试了一次,怎么图片贴不上去?
//Button button = new Button(tempComp,SWT.NONE);
//button.setImage(image);

Label label = new Label(tempComp,SWT.NONE);
label.setImage(image);

2.Re:如何在Label和Button上贴图? [Re: zf00110011] Copy to clipboard
Posted by: yipsilon
Posted on: 2006-05-19 07:00

问题出在这里:

Image image = new Image(null,strRight);

Device项不应该为null, 否则SWT无法确定这个Image用在什么地方(Display还是Printer呢?), 正确的方法是使用部件的Display. 正确的应该是这样:

Image image = new Image(photoComp.getDisplay(),strRight);

这样SWT知道这个图片是用在photoComp所使用的设备上了. 然后再用setImage(Image)方法就可以显示出来.

3.Re:如何在Label和Button上贴图? [Re: zf00110011] Copy to clipboard
Posted by: zf00110011
Posted on: 2006-05-22 11:37

Smile问题已解决,谢谢哈!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923