Adding image in java code in code name

匆匆过客 提交于 2019-12-22 09:17:14

问题


I am new in code name one. I have to add image in a container(flow layout) with specific width and height.

1: codenameone's guide says that we have to add image in resource folder. Where is that resource folder?

2: To create image i am using createImage(path) of image class. if we put image file in resource folder then what is path of that image.

3: Is here any type restriction of image file in it.

Please help.


回答1:


When you put the image you would like to add in your src folder the code should look as followed:

Label i = new Label(); Image img = Image.createImage("/imageToAdd.png"); i.setIcon(img);

You can change the label to whatever object you would like to use to display your image.




回答2:


Resource file not folder, the ".res" file in the root of the SRC directory contains your theme as well as additional images you might need. The value here is that you can add multi-images (see tutorial) as well as write very portable code.

You can access the resource file in a GUI builder via fetchResourceFile() or in a non-GUI builder app using Resources.open (as is demonstrated in the init method).

You can also place arbitrary JPG/PNG files in the src root next to the res file. While there is no restriction from Codename One, devices tend to support PNG/JPG well and might fail with other formats.



来源:https://stackoverflow.com/questions/14996693/adding-image-in-java-code-in-code-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!