简体   繁体   English

CodenameOne 无法使用 GUI Builder 将图像添加到按钮

[英]CodenameOne Cannot Add Image to Button Using GUI Builder

I am using the CodenameOne GUI builder to add an image to a button.我正在使用 CodenameOne GUI 生成器将图像添加到按钮。 I added the image to the res file and then clicked [Pick Image] in the Property Inspector (see my screenshots).我将图像添加到 res 文件,然后在 Property Inspector 中单击 [Pick Image](请参阅我的屏幕截图)。 The button image (a plus sign) appears in the GUI.按钮图像(加号)出现在 GUI 中。 I hit 'save' in the GUI Builder and then close it, then go back to NetBeans and run a debug simulation, and the icon appears, so far so good.我在 GUI Builder 中点击“保存”,然后将其关闭,然后 go 回到 NetBeans 并运行调试模拟,图标出现,到目前为止一切顺利。 . .

But now I run the debug simulation again and the button image is gone: I open the GUI Builder and it's gone there as well, the button has reverted to [Pick Image] and, when I click [Pick Image].但现在我再次运行调试模拟,按钮图像消失了:我打开 GUI Builder,它也消失了,按钮恢复为 [Pick Image],当我单击 [Pick Image] 时。 my image is missing from the res file. res 文件中缺少我的图像。

What is going on here?这里发生了什么? I repeated this three times with the same result- I literally ran the Debug sim twice without doing anything in between and the icon disappears, and there is no indication in the Output messages to indicate that there is a problem.我重复了三次并得到了相同的结果——我实际上运行了 Debug sim 两次,中间没有做任何事情,图标消失了,Output 消息中没有任何指示表明存在问题。

The Form1.gui file shows a reference to the icon image so maybe the resource file is being cleared in between makes? Form1.gui 文件显示了对图标图像的引用,所以资源文件可能在制作之间被清除了吗?

<component type="Button" icon="resFile:plus.png" name="Up" actionEvent="true">
</component>

[EDIT] I found that if I add the images using the CNO Designer on the theme.res file, the images 'stick' and I can get a good build. [编辑] 我发现如果我使用 CNO Designer 在 theme.res 文件上添加图像,图像会“粘住”并且我可以获得良好的构建。 HOWEVER, when I make code changes and then open the GUI Builder again the images are removed from the res file.但是,当我更改代码然后再次打开 GUI Builder 时,图像将从 res 文件中删除。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

can you add a code snippet of how you add the image...您可以添加有关如何添加图像的代码片段吗...

According to the error message, you may have chosen the incorrect path, or maybe you have added the path incorrectly in the code.根据错误信息,您可能选择了错误的路径,或者您在代码中添加了错误的路径。

Unfortunately, the old CN1 Designer is not compatible with the CSS compiler.不幸的是,旧的 CN1 Designer 与 CSS 编译器不兼容。 If your project uses CSS, you should add images to the resource file directly in CSS (eg by adding it as a background-image on some element), or import it via the GUI builder, as, adding it that way will also add a reference to the image inside the.css file.如果您的项目使用 CSS,您应该将图像直接添加到 CSS 中的资源文件(例如,通过将其作为背景图像添加到某些元素上),或者通过 GUI 生成器导入它,因为以这种方式添加它也会添加一个参考 .css 文件中的图像。

This stems from the CSS compiler pruning "unused" images in the resource file.这源于 CSS 编译器修剪资源文件中的“未使用”图像。 If the image isn't referenced in the CSS file anywhere, it will be removed from the output.res file.如果 CSS 文件中的任何地方都没有引用该图像,它将从 output.res 文件中删除。

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

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