Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By MuslimCoder

Thread: Vertical menu

  1. #1
    Kligham is offline Member
    Join Date
    Sep 2009
    Posts
    30
    Rep Power
    0

    Default 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

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    In what context? Like in a swing JMenu?

  3. #3
    Kligham is offline Member
    Join Date
    Sep 2009
    Posts
    30
    Rep Power
    0

    Default

    Yes in a swing JMenu.

  4. #4
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    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
    Moustafa likes this.

  5. #5
    Kligham is offline Member
    Join Date
    Sep 2009
    Posts
    30
    Rep Power
    0

    Default

    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.

    Greets
    Attached Thumbnails Attached Thumbnails Vertical menu-menu.jpg  
    Last edited by Kligham; 09-18-2009 at 10:25 PM.

  6. #6
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    I don't know how to do that, but I would look it up.

  7. #7
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    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>

  8. #8
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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.

  9. #9
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    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);
                    }
                
    //..

  10. #10
    Kligham is offline Member
    Join Date
    Sep 2009
    Posts
    30
    Rep Power
    0

    Default

    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!

  11. #11
    Dieter's Avatar
    Dieter is offline Member
    Join Date
    Sep 2009
    Posts
    91
    Rep Power
    0

    Default

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

  12. #12
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Quote Originally Posted by Kligham View Post
    On a another (dutch forum) someone stated that i could use update(g)

    Does anyone has any thoughts on this?
    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.

  13. #13
    Moustafa is offline Member
    Join Date
    Jul 2014
    Posts
    1
    Rep Power
    0

    Default Re: Vertical menu

    sorry, but the link is not working " How to Use Menus (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)"

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,004
    Rep Power
    6

    Default Re: Vertical menu

    No wonder, this thread is years old.

    now try pasting that blue text into google. You'll see magic.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Collapsible Vertical Menu
    By ccvid in forum Java Applets
    Replies: 4
    Last Post: 01-27-2009, 05:40 AM
  2. Fill a menu dynamically when menu is shown
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  3. Replies: 0
    Last Post: 07-02-2008, 08:06 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •