Solved

Displaying discriptive text to a Java component shuch as  JMenuItem or JButton, etc.

Posted on 2013-11-22
3
222 Views
Last Modified: 2013-11-23
Thank you for taking to time to read my post.

Can somebody tell me a good way to display help text for a JMenuitem or JButton?  In other words the text would be displayed in the Frame whenever a particular component is moused over or highlighted.

 I'm thinking something like itemListener or mouse listener would work but I am just not sure what the best approach is.  For example, in the program below, if I wanted to display a message "Selecting this option will close the application " when the user hovers the mouse over the JMenuItem menuItmExit, what would be the best approach to providing this type of functionality?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MyMenu extends JFrame
            implements ActionListener
{
      JMenuItem menuItmExit;
 
      public static void main(String[] args)
      {
            MyMenu mm = new MyMenu();
      }

      MyMenu()
      {
            setBounds(100,100, 300, 300);
            setTitle ("My Menu");

            JMenuBar mbar = new JMenuBar();

            JMenu menuFile = new JMenu("File");
            mbar.add(menuFile);
            
            JMenu menuView = new JMenu("View");
            mbar.add(menuView);

            JMenu menuLeaveApp = new JMenu("Leave");
            menuItmExit = new JMenuItem("Exit");
            menuItmExit.addActionListener(this);
            menuLeaveApp.add(menuItmExit);

            mbar.add(menuLeaveApp);

            setJMenuBar(mbar);

            setVisible(true);
      }

      public void actionPerformed(ActionEvent evt)
      {
            if(evt.getSource() == menuItmExit)
                  System.exit(0);
      }

}//End of class MyMenu.
0
Comment
Question by:srulison
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
krakatoa earned 500 total points
ID: 39671024
For any JComponent, you can use setToolTipText.
0
 

Author Closing Comment

by:srulison
ID: 39671489
Thank you for your help. That was a whole lot easier than I thought.
0
 
LVL 16

Expert Comment

by:krakatoa
ID: 39671520
Great.
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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 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 …

685 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