Adding image in java code in code name

混江龙づ霸主 提交于 2019-12-05 13:40:26

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.

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.

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