Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

ToolTip Text on AWT Components

  Asked By: Ella    Date: Oct 02    Category: Java    Views: 2328
  

I am developing an applet that contains three java.awt.Panels. Each
Panel is going to contain images and text. Is there any way I can
get tooltip text to appear when the mouse hovers over an image?
Unfortunately, I cannot use Swing, so I can't get to the
javax.swing.JComponent#setToolTipText method.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Velma Adams     Answered On: Oct 02

Add a MouseMotionListener or MouseListener to each panel.
In the method
public void mouseMoved(MouseEvent e) of MouseMotionListener
public void mouseEntered(MouseEvent e) of MouseListener
add some sort of popup window with your text  dsiplayed.

Frame popup;

public void mouseEntered(MouseEvent e){
if (popup == null) {
popup = new Frame();
TextArea textArea = new TextArea("Some text to display
like a tooltip.");
frame.add(popup);
frame.pack();
}else{
frame.show();
}

}
public void mouseExited(MouseEvent e){
if (popup != null) frame.hide();
}

There are all kinds of ways to do this.

You could make a class that extends MouseAdapter then override the mouse...
methods to do the above and then add an instance of it as a MouseListener
to the panel.

 
Didn't find what you were looking for? Find more on ToolTip Text on AWT Components Or get search suggestion and latest updates.




Tagged: