We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

display dialog box by clicking a menu

Halt123
Halt123 asked
on
Medium Priority
239 Views
Last Modified: 2010-03-31
Dear experts,

Is there a way to display a dialog box by clicking an option from a menu?

thank you
Comment
Watch Question

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I've had a look through here but I am still unsure how to do it
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
In the action listener for the menu use:

JOptionPane.showMessageDialog(this, "my message");

some more info:

http://javaalmanac.com/egs/javax.swing/frame_Dialog.html
Siva Prasanna KumarPrincipal Solutions Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Commented:
In the constructor for your code, you'll ned something like this. This just constructs the menu and adds an action listsner to the menu item

// Construct the menu:
JMenu menu = new JMenu();
// construct the menu items
JMenuItem item = new JMenuItem();
menu.add(item);
item.addActionListener(this);

The class in which this code is contained must implement ActionListsner's actionPerformed() method:

public void actionPerformed(ActionEvent e){
     if (e.getSource() instanceof JMenuItem)
          JOptionPane.showMessageDialog(this, "my message");
}

colr__
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.