Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

The MenuBar is always opened

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

715 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