Solved

The MenuBar is always opened

Posted on 2002-07-23
2
173 Views
Last Modified: 2012-05-04
I open other modal frame by JMenuBar when I return in my root frame. The MenuBar is always opened. how do I close it ?
CODE :
private JMenuBar menuBar;
private JMenu menuFile;
private JMenuItem JMFile;
private JMenuItem JMProg;
......
JMFile.setText("File");
menuFile.add(JMFile);
JMProg.setText("Prog");
menuFile.add(JMProg);
menuFile.setText("Menu");
menuBar.add(menuFile);
jf.setJMenuBar(menuBar);

JMFile.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt){
JFileCh.showOpenDialog(jfFile);
System.out.println( JFileCh.getSelectedFile
).toString());
//JMFile.
jf.validate();
jf.repaint();

}
0
Comment
Question by:zoltix
2 Comments
 
LVL 7

Accepted Solution

by:
Igor Bazarny earned 100 total points
Comment Utility
Hi,

Why don't you use addActionListener() instead of addMouseListener()?

Regards,
Igor Bazarny
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Looks like your problem maybe because the showOpenDialog() call does not return until the user has finished with the dialog. Thus any pending mouse listeners (such as the menu) will not get called.
Try running the dialog code in a seperate thread.

new Thread() { public void run() {
  JFileCh.showOpenDialog(jfFile);
  System.out.println( JFileCh.getSelectedFile).toString());
}}.start();
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now