如何在CN1中编写iPhone样式的弹出菜单? [英] How to code an iPhone style popup menu in CN1?
本文介绍了如何在CN1中编写iPhone样式的弹出菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它以前可能已经被介绍过,但是我什么都没用Google搜索。制作附有图片的iPhone样式的弹出选择菜单的最佳方法是什么?我已经尝试过使用对话框
,但是我还没有找到添加 Commands
的优雅方法。很好,它们都触发了动作并同时关闭了对话框。 ComponentGroup
不支持单独显示取消条目。
It has probably been covered before, but I couldn’t google anything. What is the best approach for making an iPhone-style pop-up selection menu like attached picture? I've tried with a Dialog
, but I haven't found an elegant way to add the Commands
so they appear nicely and both trigger the action and close the dialog at the same time. And showing a Cancel entry separately is not supported by a ComponentGroup
.
推荐答案
请参见以下示例:
Form hi = new Form("Pop");
Button pop = new Button("Pop");
pop.addActionListener(e -> {
Dialog dlg = new Dialog();
// makes the dialog transparent
dlg.setDialogUIID("Container");
dlg.setLayout(BoxLayout.y());
Command optionACmd = new Command("Option A");
Command optionBCmd = new Command("Option B");
Command optionCCmd = new Command("Option C");
Command cancelCmd = new Command("Cancel");
dlg.add(
ComponentGroup.enclose(
new Button(optionACmd),
new Button(optionBCmd),
new Button(optionCCmd)
)).
add(ComponentGroup.enclose(new Button(cancelCmd)));
Command result = dlg.showStretched(BorderLayout.SOUTH, true);
ToastBar.showMessage("Command " + result.getCommandName(), FontImage.MATERIAL_INFO);
});
hi.add(pop);
hi.show();
结果如下:
< a href = https://i.stack.imgur.com/pYbU8.png rel = nofollow noreferrer>
这篇关于如何在CN1中编写iPhone样式的弹出菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文