0

You may see this as a duplicate question but please here me out.

I have a JLabel with an image. This JLabel has a mouse listener binded to some function. Is there any way to make the JLabel disappear (or technically, transparent) in order for the mouse listener function to be preserved?

I know I can set a transparent image as an icon to the JLabel, but I'm wondering if there's some kind of "toggle" function out there.

kir
  • 581
  • 1
  • 6
  • 22
  • Why must "the `JLabel` disappear … in order for the mouse listener [to] function?" – trashgod Aug 15 '13 at 22:59
  • Lets say I have a border that I use to take care of resizing the window. I then want to make this border disappear/appear whenever I want, but obviously preserving its resizing function for both options. I think this is a good example. – kir Aug 15 '13 at 23:04
  • @nivde92: Can you tell me which parts are you having trouble understanding? Let's say I have a button. However I want to hide this button but it can still be clicked (if the user knows exactly where it is). Something like this but translated to JLabels. – kir Aug 15 '13 at 23:12
  • 1
    Please edit your question to include an [sscce](http://sscce.org/) that exhibits the scenario you describe. – trashgod Aug 15 '13 at 23:21
  • 1
    I'm sorry if my question is quite is hard to understand. I'll try making an sscce after I get home. – kir Aug 15 '13 at 23:37

1 Answers1

0

you could use yourLabel.setVisible(false); is not the same as dispose the frame; however, would you extend your question a little bit more or make it clearer?(I'm having a hard time trying to understand what do you want to do)

Abstract
  • 664
  • 1
  • 5
  • 15
  • See my reply on your comment. Also `setVisible(false)` seems to be removing the function also. This is probably because of how Mouse Listeners work. – kir Aug 15 '13 at 23:13
  • hmmm there's a method called setOpaque(boolean), however some swing elements doesn't work whit these, because they inherit they behavior from the look and feel that you are using, I've used Jpanels in order to make them "disapear" but all the listener still work, why you don't try to use this element instead? – Abstract Aug 15 '13 at 23:30
  • 2
    More on _opacity_ v. _transparency_ [here](http://stackoverflow.com/a/3518047/230513). – trashgod Aug 15 '13 at 23:47