Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

The MenuBar is always opened

Posted on 2002-07-23
2
Medium Priority
?
184 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

876 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