How do I add a JMenuBar to a GridBagLayout

Hi All,
I've got a GridBagLayout on a JFrame and want to add a menu bar to row 0. How do I do that? What I've tried to do is create a JPanel, add the JPanel (menuPanel) to my GridBagLayout in column 0, row 0, width 4 and height of 1. Then add the JMenuBar (bar) to menuPanel. I get the JPanel on the screen because it takes up space, but now File menu.
Please help.
// create JPanel
menuPanel = new JPanel();
constraints.fill = GridBagConstraints.BOTH;
constraints.anchor = GridBagConstraints.NORTHWEST;
constraints.weightx = 0;
constraints.weighty = 0;     
addComponent(menuPanel, 0, 0, 4, 1);  // object, row, column, width, height          
// set up  menu bar
fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
newSearch = new JMenuItem("New Search");
newSearch.setMnemonic('N');
fileMenu.add(newSearch);
exit = new JMenuItem("Exit");
exit.setMnemonic('x');
fileMenu.add(exit);
bar = new JMenuBar();
setJMenuBar(bar);
menuPanel.add(bar);Thanks,
Karl

You don't add a MenuBar to the layout, you add directly to the frame using
setJMenuBar(myMenuBar);HTH,
Radish21

Similar Messages

  • How can i add a textbox to this

    how would i add a textbox to this
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import javax.swing.border.*;
    public class Editor extends JFrame{
         JFrame frame;
         JPanel panel;
         //JTextBox field;
         JComboBox combo;
         public static void main(String[] args) {
              Editor l = new Editor();
    private JPanel pnlNorth = new JPanel(); // North quadrant
        private JPanel pnlSouth = new JPanel(); // South quadrant
        private JPanel pnlEast = new JPanel(); // East quadrant
        private JPanel pnlWest = new JPanel(); // West quadrant
        private JPanel pnlCenter = new JPanel(); // Center quadrant
    private JButton btnNorth = new JButton("Save");
        private JButton btnSouth = new JButton("Load");
        private JButton btnEast = new JButton("Head");
        private JButton btnWest = new JButton("Body");
        private JButton btnCenter = new JButton("somthing");
    private JMenuBar mb = new JMenuBar(); // Menubar
        private JMenu mnuFile = new JMenu("File"); // File Entry on Menu bar
        private JMenuItem mnuItemQuit = new JMenuItem("Quit"); // Quit sub item
        private JMenu mnuHelp = new JMenu("Help"); // Help Menu entry
        private JMenuItem mnuItemAbout = new JMenuItem("About"); // About Entry
         public Editor(){
              JFrame.setDefaultLookAndFeelDecorated(true);          
              frame = new JFrame("Editor");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              panel = new JPanel();
              //field = new JTextField(5);
    frame.setJMenuBar(mb);
    mnuFile.add(mnuItemQuit);
    mnuHelp.add(mnuItemAbout);
    mb.add(mnuFile);
    mb.add(mnuHelp);
       pnlNorth.add(btnNorth);
            pnlSouth.add(btnSouth);
            pnlEast.add(btnEast);
            pnlWest.add(btnWest);
            pnlCenter.add(btnCenter);
    frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(pnlNorth, BorderLayout.NORTH);
              frame.getContentPane().add(pnlSouth, BorderLayout.SOUTH);
            frame.getContentPane().add(pnlEast, BorderLayout.EAST);
              frame.getContentPane().add(pnlWest, BorderLayout.WEST);
              //panel.add(field);
              frame.add(panel);
              frame.setSize(300, 300);
              frame.setVisible(true);
    }

    whats the method thenyou're kidding, right? I'm not going to tell you how to do exactly what you've already been doing

  • How can I align a JMenuBar at right ?

    Hello,
    the question is very simple : How can I align a JMenuBar at right ?

    So can you try this ?
    import javax.swing.*;
    public class MenuBarDroite extends JFrame
    public MenuBarDroite()
    super();
    setSize(400,300);
    JMenuBar menu = new JMenuBar();
    menu.add(Box.createHorizontalGlue());
    JMenuItem menuItem1 = new JMenuItem("");
    JMenuItem menuItem2 = new JMenuItem("Menu 2");
    JMenuItem menuItem3 = new JMenuItem("Menu 3");
    JMenuItem menuItem4 = new JMenuItem("Menu 4");
    menu.add(menuItem1);
    menu.add(menuItem2);
    menu.add(menuItem3);
    menu.add(menuItem4);
    setJMenuBar(menu);
    public static void main(String argv[]) throws Exception
    MenuBarDroite m = new MenuBarDroite();
    m.setVisible(true);

  • How do I add URI web link with custom tooltip like "CLICK HERE TO UPDATE" instead of URI web link in tooltip.

    How do I add URI web link with custom tooltip like "CLICK HERE TO UPDATE" instead of URI web link in tooltip.

    You've probably found an answer to this by now, but I think this has been addressed in another forum -- The link below suggested using a button and adding the tooltip to the button. 
    https://forums.adobe.com/thread/304974?start=0&tstart=0
    Sounds like it would work but I haven't actually tried it. 
    Good luck~!

  • How do i add type kit fonts to muse web site

    how do I +add type kit fonts to muse website

    Hi.
    Check this video, might be helpful
    Let me know if you have any questions

  • How can I add more than one same spry menu (eg. collapsible menu)  with in different styles (font size, color, background, etc) on current page?

    How can I add more than one same spry menu (eg. collapsible menu)  with in different styles (font size, color, background, etc) on current page?

    Hi Nancy,
    This screenshot was only for imagination. A part of the code (not all) is below.  In the code there are some background images but they are not seem in live mode.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="css/my_site.css" rel="stylesheet" type="text/css" />
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css"/>
    <link href="SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
    <style>
    #CollapsiblePanel1 .CollapsiblePanelOpen .CollapsiblePanelTab {
        background-color: #003366;
        font-size: 18px;
        line-height: 52px;
        color: #FFF;
    #CollapsiblePanel1 .CollapsiblePanelTabHover .CollapsiblePanelTab {
        background-color: #003366;
        color: #FFF;
        text-shadow: 1px 1px #000;
        font-weight: bold;
        line-height: 52px;
    #CollapsiblePanel1 .CollapsiblePanelClosed .CollapsiblePanelTab  {
        background-color: #C3CFDF;
        border-radius: 5px 5px 0px 0px;
        color: #999
        text-shadow: 1px 1px #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 18px;
        font-weight: bold;
        line-height: 52px;
    #CollapsiblePanel2 .CollapsiblePanelOpen .CollapsiblePanelTab {
        background-image: url(images/international.jpg);
        background-repeat: no-repeat;
        font-size: 18px;
        line-height: 52px;
        color: #FFF;
    #CollapsiblePanel2 .CollapsiblePanelTabHover .CollapsiblePanelTab {
        background-color: #003366;
        color: #FFF;
        text-shadow: 1px 1px #000;
        font-weight: bold;
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel2 .CollapsiblePanelClosed .CollapsiblePanelTab  {
        background-color: #C3CFDF;
        border-radius: 5px 5px 0px 0px;
        color: #999
        text-shadow: 1px 1px #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 18px;
        font-weight: bold;
        background-image: url(images/TR_Gray2-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel2 .CollapsiblePanelContent {
        background-color: blue;
    #CollapsiblePanel3 .CollapsiblePanelOpen .CollapsiblePanelTab {
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        font-size: 18px;
        line-height: 52px;
        color: #FFF;
    #CollapsiblePanel3 .CollapsiblePanelTabHover .CollapsiblePanelTab {
        background-color: #003366;
        color: #FFF;
        text-shadow: 1px 1px #000;
        font-weight: bold;
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel3 .CollapsiblePanelClosed .CollapsiblePanelTab  {
        background-color: #C3CFDF;
        border-radius: 5px 5px 0px 0px;
        color: #999
        text-shadow: 1px 1px #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 18px;
        font-weight: bold;
        background-image: url(images/TR_Gray2-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel4 .CollapsiblePanelOpen .CollapsiblePanelTab {
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        font-size: 18px;
        line-height: 52px;
        color: #FFF;
    #CollapsiblePanel4 .CollapsiblePanelTabHover .CollapsiblePanelTab {
        background-color: #003366;
        color: #FFF;
        text-shadow: 1px 1px #000;
        font-weight: bold;
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel4 .CollapsiblePanelClosed .CollapsiblePanelTab  {
        background-color: #C3CFDF;
        border-radius: 5px 5px 0px 0px;
        color: #999
        text-shadow: 1px 1px #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 18px;
        font-weight: bold;
        background-image: url(images/TR_Gray2-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel5 .CollapsiblePanelOpen .CollapsiblePanelTab {
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        font-size: 18px;
        line-height: 52px;
        color: #FFF;
    #CollapsiblePanel5 .CollapsiblePanelTabHover .CollapsiblePanelTab {
        background-color: #003366;
        color: #FFF;
        text-shadow: 1px 1px #000;
        font-weight: bold;
        background-image: url(images/TR_Col-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    #CollapsiblePanel5 .CollapsiblePanelClosed .CollapsiblePanelTab  {
        background-color: #C3CFDF;
        border-radius: 5px 5px 0px 0px;
        color: #999
        text-shadow: 1px 1px #000;
        font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
        font-size: 18px;
        font-weight: bold;
        background-image: url(images/TR_Gray2-WEB.png);
        background-repeat: no-repeat;
        line-height: 52px;
    </style>

  • How do I add multiple apple id's to one account

    How do I add multiple Apple id's to one account for billing and Icloud use?

    You don't. You can't combine Apple IDs.

  • HT201342 How can I add an e-mail address to my existing icloud addresses?  I currently only use one and I would like to ad two more?

    How can I add an e-mail address to my existing icloud account?  I curently only use one of the three.

    Each iCloud account only has a single iCloud account.  If you want, you can add up to 3 alias addresses that will receive email in the same iCloud inbox, as explained here: http://support.apple.com/kb/PH2622.

  • How can I add amazon to Apple TV?

    I am a new Apple TV user. So far I am impressed and like it a lot. However I would like to use the Amazon Prime and I have yet to find it. How can I add it to my Apple TV?

    You cannot add apps to Apple TV. If you have an IOS device you can AirPlay to stream using the app from there

  • HT201269 How do I add another contact / recipient to an SMS. Easy in Android, but I can't see how on my 5s.  Have to create a group on my Macbook Pro (OS 9.1), but it's not getting synced via usb. I'd prefer not to use cloud.

    How do I add a contact / recipient to an SMS on iPhone 5s?  It's easy on Android, but I've not sussed it on the iPhone - can't create a group etc.  Tried to create a group on Mac, but it either doesn't exist or won't sync to the phone with usb, nor will other contact details created on Mac.  I'd rather not use the cloud.  I'm sure contacts used to sync to my old iPod touch in Snow Leopard.
    Is it not more logical to have the phone as the main source of this sort of data?  We're more likely to update on a device we carry all the time surely?
    Please advise. Thank you

    Hey Cornish wrinkly,
    It sounds like you want to create a group message. You can read about group messaging on the iPhone here:
    iOS: Understanding group messaging
    http://support.apple.com/kb/HT5760
    Welcome to Apple Support Communities!
    Regards,
    Delgadoh

  • How do I add multiple tickets under the same confirmation number from the American Airlines app to Passbook?

    I have a confirmation number from American Airlines for a flight with my family all under my name and for some reason I cannot add all of our tickets to Passbook. To clarify, I went to the American Airlines app and put in the confirmation number along with my name which pulled up my boarding pass only. Although I was able to add this boarding pass to Passbook, I was not able to add any of the other boarding passes for my children to Passbook that should have also been under the flight reservation. In fact I couldn't even see them in the American Airlines app. I tried to use their names and the same confirmation number but nothing happened, and nothing else seems to be working. How can I add all of these boarding passes to my Passbook?

    Fair enough.
    I started doing this before unlimited data and emails on phones was a common commodity, on my Samsung Blackjack.
    I then continued it due to its convenience. My only counter argument is this:
    Even when emails are set to immediately push, I am always notified earlier by this forwarding message (sometimes by several minutes/hours due to the fact that it is not dependent on my being connected to 4G or wifi to receive it.
    Also, to contradict snozdop's point that both methods use data and battery, I say this - when I use the forwarding method, the information comes in a pure text format and therefore uses considerably less information than an HTML and CSS rich email, with embedded images and such -also, unlimited text messages aids curve costs.
    I will, however, give this method a go. In any case, a solution to my original question would still be greatly appreciated.
    Thanks guys.

  • How do I add multiple contacts to a group?

    How do I add multiple contacts to a group on my Ipad?

    See if this thread helps.
    https://discussions.apple.com/thread/4114588
    Matt

  • How do i add a company logo to my email signature on my mac book pro

    how do i add a company logo to my email signature on my mac book pro

    I would like to know how to do this as well. All I'm able to do is add the link, but not the button. My colleague has done this on his Outlook on his HP. I'm not sure why this is so difficult!

  • How do I add a printer connected to another iMac on the network to my printer list?

    How do I add an Epson printer connected to an iMac on the network to the printer list on my MacBook Pro? I cannot get it to show up in the list for printers to add.

    That only works if the printer is itself a network printer. You can't do it if it is directly connected to another computer on the network unless it is configured to be a Shared Printer on the other computer.

  • How do i add multiple email addresses to my calendar

    How do I add multiple email addresses to my calendar on my iphone

    You can create an email alias at the mail feature at iCloud.com

Maybe you are looking for

  • Chart Line bar

    Hi I am using 11g. In 10g i have one chart report with Scale marker i set. Vertical1 and vertical2 values is dynamic.If dont have any values also it display left and right axis scale but after migrated into 11g. i am not able to see left and right sc

  • Writing an excel into message long text of se91

    does somebody know where i can write via abap fm into message long text? and where those texts are stored?

  • InCopy suddenly fails to open InDesign file

    I'm a designer working on my first book project using the InDesign/InCopy workflow, using Dropbox as our server. I share my .indd file (Mac) with one offsite editor who uses InCopy for the PC. We've been working without a glitch for about two months.

  • Embeding Regions inside Popup Windows-Pattern

    Hi folks, i'm trying to build a prototype using the "Embeding Regions inside Popup Windows"-Pattern. I've got one emp-VO on a jspx page and a popup displaying the same VO as read-only table in a region created from a fragment. The popup should be use

  • ITunes opens when I disconnect iPhone from computer... WHY?!

    Ever since the 3.1 update (I believe), whenever I disconnect my iPhone from my computer, iTunes opens... Is this Apple telling me I HAVE to have iTunes open at all times on my computer, and if I don't, they're going to open it for me? It's quite anno