• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two JLabels copying backgrounds and contents from each other on mouse over

 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm trying to create a mouseOver visual effect for several JLabel elements filled with text. The idea is to make each label darker when mouse enters and then return it to normal when the mouse leaves its area. Also all the labels are placed over a panel that has a background image.

Though simple enough, I've encountered a nasty behavior I can't overcome.

Bug 1: The first time I move mouse over a label it shows me the upper-left corner of my main window as its background.

Bug 2: Then, every time I move mouse over one label once, and then move it over the second label, the second one changes its background to the "summ background" (panel image + semitransparent background) of first label. Above that it seems that even the first label's text contents are being "copied" to the second label's background. This only happened once per label change: if I move mouse over the same label twice, the second mouse over event is painted correctly.

I've already tried to use MouseMotionListener, a different element (JButton), played with component modification methods and eve tried to override paint methods. No result.

I've attached an animated GIF showing the described behavior:


I'm relatively new to Swing so I'm not familiar with its caveats. Any idea what might cause this?


Custom Panel class:

MouseListener class:

MainWindow class:
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted: http://stackoverflow.com/questions/35423515/two-jlabels-copying-backgrounds-and-contents-from-each-other-on-mouse-over/35423681#35423681

Quit crossposting. Its annoying to spend the time answering a question only to learn the question has already been answer on another forum. We don't have time to spend on questions like this.
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to be rude.

1. When I submitted my post there were no answers on stackoverflow.
2. While others gave me the right ideas, I've answered it myself.

You're welcome to delete this thread
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!