Results 1 to 11 of 11
  1. #1
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation Mutliple JMenuBar

    Hi,

    Is this possible to implement on either JFrame or JApplet?
    Having multiple JMenuBar (like toolbars of Microsoft Office 2003) wherein you could set images as a menu.

    Thanks,
    Cyril H.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by chyrl View Post
    Is this possible to implement on either JFrame or JApplet?
    Having multiple JMenuBar (like toolbars of Microsoft Office 2003) wherein you could set images as a menu.
    Does the API documentation mention the possibility of multiple menu bars or is it talking about the menu bar?

    kind regards,

    Jos

  3. #3
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation

    Quote Originally Posted by JosAH View Post
    Does the API documentation mention the possibility of multiple menu bars or is it talking about the menu bar?

    kind regards,

    Jos
    I'm not sure of the existence. But I have seen java programs will multiple menu bars (like the standard menu bar of MS Word 2003). But I don't how it was implemented.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by chyrl View Post
    I'm not sure of the existence. But I have seen java programs will multiple menu bars (like the standard menu bar of MS Word 2003). But I don't how it was implemented.
    A JFrame (and others) implement one single menu bar as the API documentation states. You could try to add more menus to it that will fit on a single line; play and experiment with it and most important: read the API documentation.

    kind regards,

    Jos

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    You *can* add more than one JMenuBar to a parent JMenuBar after setting an appropriate layout -- possibly GridLayout(0, 1) -- and set the parent JMenuBar to a JFrame.

    db

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Darryl.Burke View Post
    You *can* add more than one JMenuBar to a parent JMenuBar after setting an appropriate layout -- possibly GridLayout(0, 1) -- and set the parent JMenuBar to a JFrame.

    db
    You mean that JMenuBars can be childs of one JMenuBar? It does implement the MenuElement interface so it should be possible ... they're all located near the top of the JFrame though.

    kind regards,

    Jos

  7. #7
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default

    Maybe you are looking to use a JToolBar?

    JToolBar (Java 2 Platform SE v1.4.2)

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Quote Originally Posted by JosAH View Post
    You mean that JMenuBars can be childs of one JMenuBar?
    Java Code:
    import java.awt.GridLayout;
    import javax.swing.*;
    
    public class NestedMenuBar {
    
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
    
          @Override
          public void run() {
            new NestedMenuBar().makeUI();
          }
        });
      }
    
      public void makeUI() {
        JMenuBar outerBar = new JMenuBar();
        outerBar.setLayout(new GridLayout(0, 1));
    
        for (int i = 0; i < 2; i++) {
          JMenu menu = new JMenu("Menu " + i);
          menu.add(new JMenuItem("Item " + i));
          JMenuBar innerBar = new JMenuBar();
          innerBar.add(menu);
          outerBar.add(innerBar);
        }
    
        JFrame frame = new JFrame();
        frame.setJMenuBar(outerBar);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 400);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    }
    db

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    Quote Originally Posted by StormyWaters View Post
    Maybe you are looking to use a JToolBar?

    JToolBar (Java 2 Platform SE v1.4.2)
    Please don't post links to Java API for old versions that are already EOL.
    JToolBar (Java Platform SE 6)

    db

  10. #10
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    306
    Rep Power
    6

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Please don't post links to Java API for old versions that are already EOL.
    JToolBar (Java Platform SE 6)

    db
    Sorry my bad. I'm forced to program using 1.4 so that's where I go for my APIs lol.

  11. #11
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Either solution of Darryl.Burke and StormyWaters solved this thread.

    Thanks.
    Cyril H.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

Similar Threads

  1. Mutliple JPanel's with an enhanced "for" loop
    By javaman1 in forum New To Java
    Replies: 4
    Last Post: 10-23-2010, 12:18 AM
  2. Changing position of JMenuBar
    By LianaN in forum New To Java
    Replies: 8
    Last Post: 09-17-2010, 12:41 PM
  3. JMenubar option
    By navishkumarb in forum New To Java
    Replies: 3
    Last Post: 05-24-2010, 02:03 AM
  4. Create JMenuBar using DataBase
    By arulmozs in forum AWT / Swing
    Replies: 1
    Last Post: 11-03-2009, 11:52 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
  •