Reputation: 77
Is it possible in Java Swing to show message box using tooltip item. I need to show tooltip not only when a mouse hovers some component but also when I choose specific item in context menu of this component when tooltips are turned off.
Upvotes: 1
Views: 1836
Reputation: 11327
You can use PopupFactory to show your popup message
final Popup p = PopupFactory.getSharedInstance().getPopup(myComponent, new JLabel("Here is my popup!"), x, y);
p.show();
// create a timer to hide the popup later
Timer t = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
p.hide();
}
});
t.setRepeats(false);
t.start();
where myComponent - is the component for which popup must be shown
x, y - coordinates of popup.
Upvotes: 4