开发者

Java: big popup menu with additional panels

开发者 https://www.devze.com 2023-02-06 01:03 出处:网络
I want to create a popup menu which has a few \"big\" (special) items. These \"big\" items should somehow behave like开发者_JAVA百科 submenus, but they are large panels (with buttons, labels, combo b

I want to create a popup menu which has a few "big" (special) items.

These "big" items should somehow behave like开发者_JAVA百科 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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消