Solved

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

Posted on 2013-11-22
3
216 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
Comment Utility
For any JComponent, you can use setToolTipText.
0
 

Author Closing Comment

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

Expert Comment

by:krakatoa
Comment Utility
Great.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now