Solved

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

Posted on 2013-11-22
3
227 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
[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
3 Comments
 
LVL 17

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 17

Expert Comment

by:krakatoa
ID: 39671520
Great.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
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 …

688 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