Welcome to Dream.In.Code
Become a Java Expert!

Join 149,594 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,860 people online right now. Registration is fast and FREE... Join Now!




JMenu Display

 
Reply to this topicStart new topic

JMenu Display, jmenu will not display

nolander
7 Oct, 2007 - 07:38 AM
Post #1

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 18


My Contributions
The code compiles without errors but the menu will not display in the window

CODE

//import classes
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;

public class JPay
{
    JFrame interfaceFrame;// variables
       JMenu menu, menuFile;
     JMenuBar menuBar;
     JMenuItem menuItem;
     Insets insets;
     Container pane;
    
    public JPay()
    {
       interfaceFrame = new JFrame("Window");
        interfaceFrame.setSize(400, 300);
        interfaceFrame.setVisible(false);
    pane = interfaceFrame.getContentPane();
      insets = pane.getInsets();
      pane.setLayout (null);
        
       menuBar = new JMenuBar();
    
        menu = new JMenu("Menu Label");
        menuBar.add(menu);

        menuItem = new JMenuItem("Item Label");
        menu.add(menuItem);
        
        interfaceFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        interfaceFrame.setVisible(true);
                
    }
   public static void main(String[] args)
    {
      new JPay();
   }
}


ta,
Nolander
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: JMenu Display
7 Oct, 2007 - 10:01 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi add this line in the constructor, say above Exit on close line

interfaceFrame.setJMenuBar(menuBar);
User is offlineProfile CardPM
+Quote Post

nolander
RE: JMenu Display
8 Oct, 2007 - 06:17 AM
Post #3

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 18


My Contributions
QUOTE(PennyBoki @ 7 Oct, 2007 - 11:01 AM) *

Hi add this line in the constructor, say above Exit on close line

interfaceFrame.setJMenuBar(menuBar);


nah didnt work, thanks anyway.
User is offlineProfile CardPM
+Quote Post

Programmist
RE: JMenu Display
8 Oct, 2007 - 06:30 AM
Post #4

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
QUOTE(nolander @ 8 Oct, 2007 - 07:17 AM) *

QUOTE(PennyBoki @ 7 Oct, 2007 - 11:01 AM) *

Hi add this line in the constructor, say above Exit on close line

interfaceFrame.setJMenuBar(menuBar);


nah didnt work, thanks anyway.

Worked for me. Try adding it to the JFrame after you've added all of the menu items.
User is offlineProfile CardPM
+Quote Post

nolander
RE: JMenu Display
8 Oct, 2007 - 06:59 AM
Post #5

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 18


My Contributions
i got it thanx
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:17PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month