• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

JMenuBar hidden...

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is that you are mixing pre-swing components (TextArea) with swing components (pretty much everything else in your GUI JMenuBar, JPanel, JFrame etc..). You should put the following before you create the JMenuBar.
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
For more info, see <http://java.sun.com/products/jfc/tsc/swingdoc-archive/mixing.html>;
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the link got lost in that last post. Here it is again.
http://java.sun.com/products/jfc/tsc/swingdoc-archive/mixing.html
Tim
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The AWT Components are Heavyweight which means that they are directly associated with an underlying peer component of the operating system. Many of the Swing components are lightweight to allow them to appear more uniform from OS to OS. However the heavyweight stuff clobbers them.
You should try to stick to all one or the other.
 
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic