• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on Tooltip

 
Satheesh Thekku Veethil
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am trying to write an application with tooltip feature on some of the components.
Now by default the tooltip comes up when there is a mouse over on the component. I want to change this aspect and get the tooltip on a mouse pressed event on the component. In fact when the user keeps the mouse pressed for a stipulated time, the tooltip is shown.
Any ideas on how I can accomplish this feature?
Please respond at the earliest.
Thanks
Sat
 
ashish kulkarni
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
By default keep the tooltip disabled,
and when user clicks a component on which u want to show the tooltip , then enable it
and when the user releases the mouse, again disable tooltip
 
Satheesh Thekku Veethil
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashish
I tried ur suggestion. But it doesn't work.
Here's the code of the test program that i tried.
See if there is something i am missing
Thanks
Sat

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TooltipTest
{
JFrame frame;
JPanel panel;
JButton button1;
JButton button2;
TooltipTest()
{
frame = new JFrame();
panel = new JPanel();
button1 = new JButton("THIS IS TEST BUTTON1")
button2 = new JButton("THIS IS TEST BUTTON2");
button1.setToolTipText("This is a text tool tip for button 2");
button2.setToolTipText("This is a text tool tip for button 2");
ToolTipManager.sharedInstance.setEnabled(false);
button1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent event)
{
System.out.println("Inside Mouse Pressed");
ToolTipManager.sharedInstance.setEnabled(true);
}
public void mouseReleased(MouseEvent event)
{
System.out.println("Inside Mouse Released"); ToolTipManager.sharedInstance.setEnabled(true);
}
});
panel.setLayout(new FlowLayout());
panel.add(button1);
panel.add(button2);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String args[])
{
TooltipTest t = new TooltipTest();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!