?
Solved

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

Posted on 2013-11-22
3
Medium Priority
?
233 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 16

Accepted Solution

by:
krakatoa earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

741 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