1
\$\begingroup\$

The JLabel has an image of a room. I want the mouse to act as a flashlight, and only display around the mouse the part of the JLabel/image that the mouse is hovering over, in a large circumference.

How do I make a part of the JLabel, relative to the position of the mouse, visible only under the location of the mouse?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There are a few different solutions on Stack Overflow that describe in detail how to do this:

Personally, I think the RadialGradientPaint solution is the one best suited to your needs, since it can make it so that the edges are dimmer than the center, which better emulates the flashlight effect you are looking for.

\$\endgroup\$
3
  • \$\begingroup\$ Is it possible to get a usage example for the RadialGradientPaint? \$\endgroup\$
    – Charanor
    Commented Feb 2, 2017 at 10:40
  • \$\begingroup\$ @Charanor There is a full example on Stack Overflow at that link. \$\endgroup\$ Commented Feb 2, 2017 at 15:18
  • \$\begingroup\$ Oh I see, I'm on the phone and the app didn't make the text blue to indicate a link. All well:) \$\endgroup\$
    – Charanor
    Commented Feb 2, 2017 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .