Java:带有附加面板的大弹出菜单
我想创建一个弹出菜单,其中有一些“大”(特殊)项目。
这些“大”项目应该以某种方式表现得像子菜单,但它们是大面板(带有按钮、标签、组合框等)。当鼠标悬停(或按下)相应的菜单项时,这些面板都应该出现,并且它们都应该出现在弹出菜单旁边的同一屏幕区域中,位于最上面的项目条目下方,而不是与其相应的项目对齐) 。只要弹出窗口可见,最后选择的选项就可以保持可见。
基本上,我相信这感觉就像(A)在弹出菜单旁边放置一个JLayeredPane,并根据一些鼠标事件切换图层。可能这需要在 JPopupMenu 中使用单个大型 JPanel 来伪造整个弹出菜单,其中只有一个条目(即所有“普通”菜单项实际上都必须是按钮。)
因此,另一方面 (B),使用标准摆动子菜单项似乎更聪明,将大面板添加为子菜单项,然后强制所有子菜单项位于相同的位置和大小。不过,我不确定这是否可行,以及是否会出现这样的问题,例如一旦用户单击其中一个大面板内的组合框,菜单就会立即隐藏。
您会建议选择 (A) 或 (B) - 或者也许选择 (C) ?
做这样的事情有什么经验/已知的陷阱吗?
亲切的问候, 菲利普
I want to create a popup menu which has a few "big" (special) items.
These "big" items should somehow behave like submenus, but they are large panels (with buttons, labels, combo boxes, etc.). These panels should all appear when the mouse is over (or pressed at) the corresponding menu items, and they all should appear in the same screen area just next to the popup menu, beneath the topmost item entry, not aligned to their corresponding item). The last-selected of them can remain visible as long as the popup is visible.
Basically, I believe this feels like (A) putting a JLayeredPane next to the popup menu, and switching the layers according to some mouse events. Probably this would require to fake the whole popup menu using a single large JPanel inside a JPopupMenu having just this one entry (i.e. also all "ordinary" menu items would in fact have to be buttons.)
So, on the other hand (B), it seems probably smarter to use standard swing submenu items, add the big panels as submenu items, and then force all the submenu items to the same location and size. Though, I am not sure if this will work and whether there will be such problems like the menu getting instantly hidden as soon as the user clicks a combo box inside one of the big panels.
Would you recommend going for either (A) or (B) — or perhaps (C) ?
Any experiences / known pitfalls doing such things?
Kind regards,
Philipp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有 A 或 B 的经验,但在两者之间我会先尝试 B。
另一个可能更好的选择是使用 JDialog。设置为未修饰并在失去焦点时将其隐藏。 (这可能是实现 A 的更简单的方法)。
I don't have experience with A or B, but between the two I would try B first.
Another option that might be better is to use a JDialog. Set to to be undecorated and hide it when it loses focus. (This might just be an easier way to do A).