I want to create a JPopupMenu that has a few items on it. Instead of rectangular layout of menu I it to open in circular manner and when I click one of the items on menu if it has any sub menu item then it should as a wrapper circular menu again out of the main menu.
I tried but was unable to achieve the requirement.
For reference please see the attached images:
File. Edit and Format are the main menu items. Cut, Copy and Paste are sub-menu items for each.
Related
I have this requirement where I need to show menus which can go multiple levels down. Now at each level there can be many objects in the menu which means I have to show a scroll bar in the menu.
1
1->1
1->2
2
I am able to write a custom class 'JScrollPopupMenu' which introduces a scroll bar to the menu. Now I can only control the first pop-up menu but for the next level menus I have no control over the pop-up menu being created
Example:
//this is the first pop-up menu
JPopupMenu scrollablePopupMenu = new JScrollPopupMenu();
JMenu menu = new JMenu("1");
scrollablePopupMenu.add(menu);
menu = new JMenu("2");
scrollablePopupMenu.add(menu);
//this is the child menu for "1", I have no control over //childMenu.getPopupMenu(), this is created internally inside JMenu
JMenu childMenu = new JMenu("1->1");
menu.add(childMenu);
childMenu = new JMenu("1->2");
menu.add(childMenu);
In the above example, the first level pop-up has a scroll bar but the next level pop-up does not. Is there any way how this can be achieved?
If you have that many menu items you should reconsider your GUI design.
1) A thumb-rule in usability says that you should not display more than 8 selections in a group.
2) Just because Windows have a scrollable menu in the Start-menu, doesn't make it a good example. In fact, Microsoft has left that in favour of searching instead, just be because a huge scrollable menu isn't user-friendly.
I have 3 conditions (3 menu items in menu). In those 3 items, how to get one menu item selected as soon as the frame opens and displays the content of that item by default?
Later on if we select other menu items, then corresponding contents on the frame will be displayed as usual. I have written very lengthy code for this GUI, so unable to paste here. But got stuck up at this point.
Simply invoke the actionPerformed() method of your ActionListener after your GUI is fully constructed. This is particularly easy if you have implemented the Action interface, as shown in How to Use Actions.
Using this example, add the following line near setVisible() to simulate adding a few random nodes to the graph:
gp.control.random.actionPerformed(new ActionEvent(gp, 0, null));
To simulate clicking a button, this line simulates adding a selected node:
gp.control.defaultButton.doClick();
By default all menu items are not selected when they are created. To make a menu item selected before you show it in your application you should change the state of the model. For the JMenu items it's easy by setSelected(true) and setPopupMenuVisible(true). For the JMenuItem items you have to setArmed(true). You can return back to the default state in the actionPerformed.
Is it possible to have a collapsible menu in a fragment, say for example...
Drinks
Juice
Soda
Main Dish
Spaghetti Carbonara
Pizzas
What I want to achieve is that, when I click the main menu "Drinks", I will collapse to show the submenu items.
If the collapsible thing is not possible, is it possible to hide the main menu then show only the submenus under the chosen main menu item?
for eg.
When I click the "Drinks" on the main menu, I will re-populate (well I don't know what's it called) the fragment with the submenu items. Is this achievable?
I read something about Fragments that I could not put another fragment on top of another one. Is this true?
I believe you are looking for an ExpandableListView.
i want to add a popup menu to my app but when i add it to my panel i see its disappear.
how i can edit jpopup menu visualy like other menus?
I think you're talking about using the matisse visual designer in NetBeans.
In which case the process is slightly different from creating menubar menus that you can just drag onto the screen.
The steps to get this to work are as follows
Drag a pop up menu on to the screen
Go to the Inspector Window (Window -> Navigating -> Inspector)
You will see an element there - jPopupMenu1
Right click jPopupMenu1 -> Add from Palette
This submenu will show you all the items that can be added to your pop-up menu
After you have selected the item you will see it listed as a child node of jPopupMenu1.
To change the order of your menu items, select an item, right click and select move up or move down.
Don't forget that although you've added the pop-up menu to the form you still need to register the pop-up menu with the component that you want it to activate for, the easiest way to do so is via SetComponentPopupMenu().
My problem is this
I want to show a popup menu to a menu item in java, this i can easily achieve,
but when i am showing the popup menu the parent menu clears,
behaviour i want is parent menu also should be visible while showing popup menu
May I first ask "why"? It seems like very uncommon, thus bad usability. There's a good reason why you don't see this in any main stream application. If you want submenu, use submenu like trashgod's sample.
You can add a PopupMenuListener to your parent menu's popup menu, break at popupMenuWillBecomeInvisible and see the call stack. In JDK6, It comes from BasicMenuItemUI#doClick calling MenuSelectionManager#clearSelectedPath.
So if you really have a good reason to surprise user, supply your own menu item UI.
I'm looking at two demos, PopupMenuDemo and GraphPanel, and I don't see any clearing. PopupMenuDemo shows a hierarchical submenu, while GraphPanel shows a hierarchical context menu. Do you have an example in which "the parent menu clears."
Addendum: Here's what I see for PopupMenuDemo. Neither demo appears to invoke setVisible() on the menu.