- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以在代号为 One 的 Dialog.show 中插入图像吗?如果是的话,有人可以提供一个例子吗
这就是我想出的:
img.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Dialog.show("Image:", images(value.toString()), new Command("Cancel"));
}
});
public ImageViewer images(String id) {
int id2 = Integer.parseInt(id);
String img = ServiceTask.getInstance().ReturnImage(id2);
Image placeholder = Image.createImage(getWidth() / 3 - 4, getWidth() / 3 - 4, 0xbfc9d2);
EncodedImage encImage = EncodedImage.createFromImage(placeholder, false);
ImageViewer img1 = new ImageViewer(URLImage.createToStorage(encImage, "file" + img,
"http://localhost/projectname/web/images/" + img));
return img1;
}
最佳答案
在您的代码中,您使用了 ImageViewer
: 我不确定它是否适合放在 Dialog
中.但是要小心:ImageViewer
和 URLImage
如果您想要最高分辨率的照片,则不适合一起使用,因为URLImage
总是调整图像大小。
让我们从显示图像的 Dialog 的简单示例开始:
Form hi = new Form("Hi World", BoxLayout.y());
Button btn = new Button("Tap me to show Dialog");
hi.add(btn);
hi.show();
btn.addActionListener(l -> {
Dialog dialog = new Dialog("Example", BoxLayout.y());
dialog.add(new SpanLabel("Example of Dialog including an image"));
dialog.add(new Label(FontImage.createMaterial(FontImage.MATERIAL_RADIO, "Label", 7.0f)));
dialog.setDisposeWhenPointerOutOfBounds(true);
dialog.show();
});
URLImage
,就像在您的代码中一样,您可以使用它:
Form hi = new Form("Hi World", BoxLayout.y());
Button btn = new Button("Tap me to show Dialog");
hi.add(btn);
hi.show();
btn.addActionListener(l -> {
Dialog dialog = new Dialog("Example", BoxLayout.y());
dialog.add(new SpanLabel("Example of Dialog including an image"));
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(CN.convertToPixels(30), CN.convertToPixels(30), 0x00ffffff), true);
URLImage meditationIcon = URLImage.createToStorage(placeholder, "gnu_meditation_levitation_small.png",
"https://www.informatica-libera.net/immagini/gnu_meditation_levitation_small.png", URLImage.RESIZE_SCALE_TO_FILL);
meditationIcon.fetch();
dialog.add(FlowLayout.encloseCenter(new Label(meditationIcon)));
dialog.setDisposeWhenPointerOutOfBounds(true);
dialog.show();
});
Dialog
显示图像应该立即显示,所以
URLImage
在这种情况下不是一个好的选择。在类似的情况下,我更喜欢预下载图像,如下面的代码所示。结果是一样的,但是当
Dialog
时图像已经下载了显示(否则不显示):
Form hi = new Form("Hi World", BoxLayout.y());
Button btn = new Button("Tap me to show Dialog");
hi.add(btn);
hi.show();
AsyncResource<Image> myImage = Util.downloadImageToStorage("https://www.informatica-libera.net/immagini/gnu_meditation_levitation_small.png", "myImage.png");
btn.addActionListener(l -> {
Dialog dialog = new Dialog("Example", BoxLayout.y());
dialog.add(new SpanLabel("Example of Dialog including an image"));
try {
// Very small timeout (10 ms), if the Image wasn't pre-downloaded it will not be shown
dialog.add(FlowLayout.encloseCenter(new Label(myImage.get(10).scaledWidth(CN.convertToPixels(30)))));
} catch (InterruptedException ex) {
Log.e(ex);
}
dialog.setDisposeWhenPointerOutOfBounds(true);
dialog.show();
});
Form hi = new Form("Hi World", BoxLayout.y());
Button btn = new Button("Tap me to show Dialog");
hi.add(btn);
hi.show();
AsyncResource<Image> myImage = Util.downloadImageToStorage("https://www.informatica-libera.net/immagini/gnu_meditation_levitation_small.png", "myImage.png");
btn.addActionListener(l -> {
Dialog dialog = new Dialog("Example", BoxLayout.y());
dialog.add(new SpanLabel("Example of Dialog including an image"));
try {
// Very small timeout (10 ms), if the Image wasn't pre-downloaded it will not be shown
dialog.add(FlowLayout.encloseCenter(new Label(myImage.get(10).scaledWidth(CN.convertToPixels(30)))));
} catch (InterruptedException ex) {
Log.e(ex);
}
Button cancel = new Button("Cancel");
cancel.addActionListener(ll -> dialog.dispose());
dialog.add(cancel);
dialog.show();
});
Dialog
如您所愿,CSS 是一个不错的选择。
关于java - 我可以在代号为 One 的 Dialog.show 中插入图像吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61812115/
我正在尝试使用 Eclipse 和 codename one 跨平台环境建立与数据库的在线连接。 很明显,将本地数据库放在默认文件夹中可以让您访问数据库,连接代码如下: db = Display.ge
我正在尝试通过代码在我的应用程序上打开侧面菜单。 我的表单使用工具栏用更复杂的组件填充侧面菜单。 我用它来关闭菜单: SideMenuBar.closeCurrentMenu(); 但我找不到等效的打
我正在使用 Codename One 开发移动应用。 我有一个外部容器,我通过调用方法 addPointerReleasedListener 添加了一个 ActionListener。 还有更多未添加
现在我正在使用 Codename one Calendar API,它工作正常,但我在日历 ui 方面遇到了一些设计问题。我的要求是当我点击特定的一天并将其添加为事件日时,那么该日的颜色就会改变。 以
我正在 Samsung Galaxy Tab A 10.1 (2019) 上测试我的应用(调试版本)。设备分辨率为 1200 x 1920。但是,当我使用 getDisplayWidth() 和 ge
我正在用 Textfield 创建一个 GenericListCellRenderer,我需要编辑 textfield 并替换其中的值,但我没有单击 Textfield 时获得任何焦点。我试过的代码如
Codename One动画发生了什么?我使用了很多,自12月起,我的应用程序不再起作用。当我在六月离开东西时,一切都很好(至今已经一年多了)。 我的应用程序是草稿(跳棋)游戏,自2013年以来在应用
我正在尝试为 Android 发布我的 Codename One-built 应用程序,但在尝试上传新版本(发布 apk 或 aab)时,我卡在了 Google Play 控制台上。 自 2021 年
我正在尝试在 Codename One 中使用计时器,但它只有“UITimer”,我似乎无法弄清楚也找不到任何示例。 所以我尝试了 Swing 计时器,但它给了我错误: codename1.ui.ev
我的应用程序构建正常,但是当我添加库 parse4cn1 时,构建失败 ios 失败示例: CompileC build/Main.build/Release-iphoneos/Main.build/
在代号一中,我试图实现一张用户卡,其中包含一些描述和两个操作按钮(调用和短信),位于卡的底部,彼此水平放置。有没有办法“分割”最后一个文本行?帮助会很棒! 谢谢! 最佳答案 您可以将这 2 个按钮放置
我目前正在用代号一写一个简单的游戏,我希望用户选择国家。 我希望在可滚动列表中将国家表示为图像。 我有一个在 X 轴上带有 BoxLayout 的容器,以及内部带有图标的按钮。 问题是不适合容器的列表
我正在尝试使用 setBrowserNavigationCallback BrowserComponent 的方法从 html 页面调用 java 方法。 这就是我在java中的内容:
我尝试将我的 Codename One 应用程序发送到构建服务器来构建 Android 应用程序,但它一直失败。一切在模拟器上运行良好,没有错误。唯一的问题是当我尝试将项目发送到构建服务器时。这是错误
我正在尝试以代号一创建一个音乐播放应用程序,在向媒体播放器添加 slider 时遇到问题。应用程序运行时会显示 slider ,但播放文件时不会显示进度。这是我用来添加自定义播放和暂停按钮以及 sli
我习惯用 Java 开发桌面应用程序。现在我正在尝试使用 Codename One 开发我的第一个移动应用程序。 在尝试复制我在 SQL 数据库方面的经验时,我遇到了一种非常奇怪的存储行为,我无法解释
我正在尝试使用我的 cn1 android 应用程序获取推送通知。我让它在 ios 上完美运行,但出于某种原因,它甚至没有在 android 上注册。这是我做的 我在我的 Play 商店控制台中启动了
我在 iPhone 7 上运行了一个代号为 one 的程序。那部手机最近没电了,我得到了 iPhone11 pro。我从旧手机中删除了 UDID,并将新手机的 UDID 添加到我的苹果开发者帐户中。我
我有一个图标按钮,带有一个小方形图标。 按钮嵌入在 BoxLayout 中。 有没有办法减小按钮的大小,以便自动达到图标的准确大小? 我的意思是,我知道我可以更改按钮的大小编辑边距和填充,但我想问我是
我正在创建一个媒体播放器应用程序,该应用程序应该从远程 URL 流式传输 mp3 文件。问题是,在代号为一个模拟器上一切正常,但在实际的 Android 设备上却不行。我希望该应用程序能够像模拟器上一
我是一名优秀的程序员,十分优秀!