srulison
asked on
Displaying discriptive text to a Java component shuch as JMenuItem or JButton, etc.
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.addActionListe ner(this);
menuLeaveApp.add(menuItmEx it);
mbar.add(menuLeaveApp);
setJMenuBar(mbar);
setVisible(true);
}
public void actionPerformed(ActionEven t evt)
{
if(evt.getSource() == menuItmExit)
System.exit(0);
}
}//End of class MyMenu.
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.addActionListe
menuLeaveApp.add(menuItmEx
mbar.add(menuLeaveApp);
setJMenuBar(mbar);
setVisible(true);
}
public void actionPerformed(ActionEven
{
if(evt.getSource() == menuItmExit)
System.exit(0);
}
}//End of class MyMenu.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great.
ASKER