This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JMenuBar hidden... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JMenuBar hidden..." Watch "JMenuBar hidden..." New topic
Author

JMenuBar hidden...

Ram Sita
Greenhorn

Joined: Jul 14, 2001
Posts: 3
I have incorporated a TextArea in the panel of my JFrame that also has a Canvas and numerous button. When I attempt to access the JMenuItems from the menu bar, the options are hidden under the TextArea. I've tried adding the JMenuBar as the last segment of code, but that seems to have no affect. If you run the code below and try to access the File menu, you'll see what I mean. SOMEONE PLEASE HELP!!
import java.awt.event.*;
import java.io.*;
import java.awt.Window;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.lang.*;

public class getHelp
{
JLabel statusBar;
JMenuItem Open;
JMenuItem Close;
JMenuItem Save;
JMenuItem SaveAs;
JMenuItem Print;
JMenuItem Exit;
JMenuItem Undo;
JMenuItem Mode;
JMenuItem Index;
JMenuItem About;
JMenuItem ClearText;
JMenuItem ClearScreen;
JMenuItem Execute;
JButton Exec;
JButton ClrTxt;
JButton ClrScrn;
JButton Toggle;
JButton Load;
JButton Prnt;
int toggleCounter = 0;
TextArea textPane;
JPanel panel;
JPanel p;
JPanel p4;
TextField instructionField;
JLabel instFieldLabel;
//parser instructionParser = new parser();

public static void main(String[] args)
{
getHelpuserInterface = new getHelp();
userInterface.init();
}
private void init()
{
JFrame frame = new JFrame("HelpMe");

frame.addWindowListener(new BasicWindowMonitor());
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
//JMenu editMenu = new JMenu("Edit");
JMenu toolsMenu = new JMenu("Tools");
JMenu helpMenu = new JMenu("Help");
Open = new JMenuItem("Open");
Close = new JMenuItem("Close");
//Save = new JMenuItem("Save");
SaveAs = new JMenuItem("Save As...");
Print = new JMenuItem("Print");
Exit = new JMenuItem("Exit");
//Undo = new JMenuItem("Undo");
Mode = new JMenuItem("Switch Mode");
ClearText = new JMenuItem("Clear Text");
ClearScreen = new JMenuItem("Clear Screen");
Execute = new JMenuItem("Execute");
Index = new JMenuItem("Index");
About = new JMenuItem("About TurtleWorld2001");

fileMenu.add(Open);
fileMenu.add(Close);
//fileMenu.add(Save);
fileMenu.add(SaveAs);
fileMenu.add(Print);
fileMenu.add(Exit);
//editMenu.add(Undo);
toolsMenu.add(Mode);
toolsMenu.add(ClearText);
toolsMenu.add(ClearScreen);
toolsMenu.add(Execute);
helpMenu.add(Index);
helpMenu.add(About);
//Container contentPane = frame.getContentPane();
//contentPane.setSize(850,500);
//contentPane.setLayout(new GridLayout(1,3));
//contentPane.add("Center", new JButton("Main application area"));
//JPanel content = (JPanel)frame.getContentPane();
panel = new JPanel();
//panel.setLayout(new GridLayout(1,3));

panel.setLayout(new BorderLayout());
//content.setLayout(new GridLayout(2,1));
p = new JPanel();
p.setSize(50,50);
p.add(new JLabel("Command Screen"));
//p.add();
textPane = new TextArea("", 1000, 30, TextArea.SCROLLBARS_VERTICAL_ONLY);
//textPane.setSize(50,100);
instFieldLabel = new JLabel("Enter Instruction: ", Label.RIGHT);
instructionField = new TextField(30);
p4 = new JPanel();
p4.add(instFieldLabel);
p4.add(instructionField);
panel.add(p4, BorderLayout.SOUTH);
// p4.setVisible(true);

//panel.add(instFieldLabel, BorderLayout.SOUTH);
//panel.add(instructionField, BorderLayout.SOUTH);
panel.add(textPane, BorderLayout.WEST);
//panel.add(p);
//**********CHANGE TO panel.add(textPane)*************************//
//JPanel content2 = (JPanel)frame.getContentPane();
//content.setLayout(new GridLayout(2,1));
JPanel p2 = new JPanel();
p2.setSize(500,250);
//panel.add(p2, BorderLayout.CENTER);
Canvas floor = new Canvas();
floor.setBackground(Color.black);
floor.setSize(500, 450);
p2.add(floor);
panel.add(p2, BorderLayout.CENTER);

JPanel p3 = new JPanel();
//p3.setSize(250,250);
p3.setLayout(new GridLayout(6, 1, 5, 5));
Exec = new JButton("Execute");
ClrTxt = new JButton("Clear Text");
ClrScrn = new JButton("Clear Screen");
Toggle = new JButton("Toggle Mode");
Load = new JButton("Load file...");
Prnt = new JButton("Print");
Exec.setVisible(true);
ClrTxt.setVisible(true);
ClrScrn.setVisible(true);
Toggle.setVisible(true);
Load.setVisible(true);
Prnt.setVisible(true);
p3.add(Exec);
p3.add(ClrTxt);
p3.add(ClrScrn);
p3.add(Toggle);
p3.add(Load);
p3.add(Prnt);
panel.add(p3, BorderLayout.EAST);
p.setBorder(new LineBorder(Color.red));
p2.setBorder(new LineBorder(Color.black));
p3.setBorder(new LineBorder(Color.blue));

frame.setContentPane(panel);
menuBar.add(fileMenu);
menuBar.add(toolsMenu);
menuBar.add(helpMenu);
frame.setJMenuBar(menuBar);
menuBar.setVisible(true);
//statusBar = new JLabel(" ");
//statusBar.setVisible(true);
frame.setSize(900,550);
frame.setVisible(true);
instFieldLabel.setVisible(false);
instructionField.setVisible(false);
}
}
class BasicWindowMonitor extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
Window w = e.getWindow();
w.setVisible(false);
w.dispose();
System.exit(0);
}
}
Lucas Richardson
Ranch Hand

Joined: Jul 08, 2001
Posts: 32
You've mixed an AWT component in with your swing components. Try not to do this. The peer component that is created for your textArea will be on top of any swing components that you have. You should use either all swing or all awt.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenuBar hidden...
 
Similar Threads
how to create a search engine?
jmenubar,menuitem
Opening a new window.
JMenuBar hidden...
JMenuBar hidden...