Solved

The MenuBar is always opened

Posted on 2002-07-23
2
174 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
ID: 7172427
Hi,

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

Regards,
Igor Bazarny
0
 
LVL 92

Expert Comment

by:objects
ID: 7173201
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

861 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

25 Experts available now in Live!

Get 1:1 Help Now