0

I want to set a tooltip at an specific location at my picture. and then once I do that I want to then if the user clicks the tooltip then a picture pops up basically. Here's my code. My question is how do I make a "invisible button" basically invisible box from point x to point y

//********************************************************************
//  TransitMap.java       Authors: Lewis/Loftus
//
//  Demonstrates the use a scroll 
//********************************************************************

import java.awt.*;
import javax.swing.*;

public class TransitMap
{
   //-----------------------------------------------------------------
   //  Presents a frame containing a scroll pane used to view a large
   //  map of the New York transit system.
   //-----------------------------------------------------------------
   public static void main(String[] args)
   {
      JFrame frame = new JFrame("New York Transit Map");

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      ImageIcon image = new ImageIcon("fortress.jpg");
      JLabel imageLabel = new JLabel(image);

      JScrollPane sp = new JScrollPane(imageLabel);
      sp.setPreferredSize(new Dimension(450, 400));

      frame.getContentPane().add(sp);
      frame.pack();
      frame.setVisible(true);
   }

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Usman Bashiru
  • 125
  • 2
  • 9

1 Answers1

0

In order to get a tooltip at a specific location on a JComponent you need to override the JComponent.getToolTipText(MouseEvent). This will get called if you register your JComponent to the ToolTipManager with ToolTipManager.registerComponent(JComponent)

To make the tooltip clickable is a bigger problem, but I found an question here on SO that got an accepted answer on how to do this. Have not tested it myself though.

Community
  • 1
  • 1
gustf
  • 1,959
  • 13
  • 20