Solved

The MenuBar is always opened

Posted on 2002-07-23
2
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

615 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