Results 1 to 12 of 12
Thread: Vertical menu
- 09-18-2009, 06:13 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 30
- Rep Power
- 0
Vertical menu
Hello,
I was wondering if it is possible to make a vertical menu instead of a normal horizontal one. Like this:
Menu 1
Menu 2
Menu 3
And when you then click on one of them you get:
Menu1
Menu2
Menui tem 1
Menui tem 2
Menui tem 3
Menu 3
Is this possible and if so, can someone help me in the right direction or give me a hint.
Greets
- 09-18-2009, 07:03 PM #2
In what context? Like in a swing JMenu?
- 09-18-2009, 07:39 PM #3
Member
- Join Date
- Sep 2009
- Posts
- 30
- Rep Power
- 0
Yes in a swing JMenu.
- 09-18-2009, 10:15 PM #4
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
It's your lucky day, I got to stumble over that some days ago; Alhamdulillah I got to remember where it was:
How to Use Menus (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)
All the best
- 09-18-2009, 10:22 PM #5
Member
- Join Date
- Sep 2009
- Posts
- 30
- Rep Power
- 0
Hello,
Thanks for the link. It is a vertical menu, but the menuitems popup to the right. I want to have them popup down (like in a normal horizontal menu) so that the other menus are pushed down (under the pressure of those menu items).
For making things a bit clearer, this is what i have in mind: see picture.
GreetsLast edited by Kligham; 09-18-2009 at 10:25 PM.
- 09-18-2009, 11:24 PM #6
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
I don't know how to do that, but I would look it up.
- 09-18-2009, 11:27 PM #7
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
Here is a something you could try out, it says in the tutorial that
"Another way of changing the look of menus is to change the layout managers used to control them. For example, you can change a menu bar's layout manager from the default left-to-right BoxLayout to something such as GridLayout."
How about changing the not only the menu Bar's layout, but the JMenu Layout to GridLayout.
I hope it helps<smile>
- 09-19-2009, 01:50 AM #8
The only thing I can think of is adding and removing JMenuItems on the fly, but I don't know if it would update the screen on the fly -- prob. not, but I have not tested it.
- 09-19-2009, 06:37 AM #9
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
Here is the code they used to make the other menu:
http://java.sun.com/docs/books/tutor...ayoutDemo.java
I made some modification's Alhamdulillah and got it to work by popping the menu downward. The only thing left is the push the other menu's down
Java Code:// MenuLayoutDemo.java // ... public void setPopupMenuVisible(boolean b) { boolean isVisible = isPopupMenuVisible(); if (b != isVisible) { if ((b==true) && isShowing()) { //Set location of popupMenu (pulldown or pullright). //Perhaps this should be dictated by L&F. int x = 0; int y = 0; Container parent = getParent(); // for sub menus if (parent instanceof JPopupMenu) { /* x = 0; y = getHeight();*/ x = getHeight(); y = 0; //..glue other components to the end } else { /* x = getWidth(); y = 0;*/ x = 0; y = getHeight(); //..glue other components to the end } getPopupMenu().show(this, x, y); } else { getPopupMenu().setVisible(false); } //..
- 09-25-2009, 10:29 AM #10
Member
- Join Date
- Sep 2009
- Posts
- 30
- Rep Power
- 0
Hi,
First of all, sorry for the long reply time, but I had alot of my mind, and thanks for the help in previous posts =p
I tested it and it does pop the menu downward, but like you said, the other menu's don't push the others downwards. So does anyone can help me further on this? If this is possible or not.
On a another (dutch forum) someone stated that i could use update(g), but he also says that it would be alot of work to make it possible. Does anyone has any thoughts on this?
Help is greatly appreciated!
- 09-25-2009, 11:15 AM #11
are there also dutch java forums? :o
Programming today is a race between software engineers striving to build bigger and better idiot proof programs,and the Universe trying to produce bigger and better idiots...
- 09-25-2009, 04:49 PM #12
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Yes, never override update(...). That is an old AWT trick and should not be used on Swing.
First you need to understand your requirement and you need to understand how Swing works.
When using Swing you add components to a container. That is you add a JMenu to a JMenuBar. Then you add JMenuItems to a JMenu. When you click the JMenu, a JPopupMenu is created with all the menu items and the component is painted on the JLayeredPane.POPUP_LAYER.
What you want to do is basically insert the JPopupMenu into the JMenuBar after the JMenu that was clicked. Presumably you will then also need some way to remove the popup menu from the menubar when a menu item is clicked.
I don't know the best way to do this.
Similar Threads
-
Collapsible Vertical Menu
By ccvid in forum Java AppletsReplies: 4Last Post: 01-27-2009, 05:40 AM -
Fill a menu dynamically when menu is shown
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:47 PM -
How to use vertical and horizontal sliders in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM -
React to menu action and checkbox menu
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:50 PM -
how to create Popup Menu with Sub Menu while right-clicking the JTree Node??
By Kabiraa in forum AWT / SwingReplies: 7Last Post: 05-09-2008, 07:54 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks