Dumb Swing question

It's been awhile since I used Swing, and that wasn't very much. I have a fairly basic question. I want a mouseover sound to play in my UI when a user mouses over my buttons. Is there an easier way to acheive this without adding a MouseListener to the button? It's not that big of a deal, but it seems a bit of waste just to add a sound to the mouseEntered event.

Just want to make sure I'm not missing something obvious.

Many thanks,


Adding a mouse listener to catch ENTER and LEAVE events is fine. You can even use a single listener for all buttons…

Ok. Thing is I have different sounds for different buttons, so one listener won't cut it. I guess the thing that concerned me was that when I add a mouse listener, it makes me implement mouseClicked, mouseReleased, mousePressed, mouseEntered, mouseExited when all I really need is entered and clicked. Just seemed like a bit of extra overhead when you multiply it by many buttons (my game is UI intensive).

Then just use the Adapter instead of the Interface :slight_smile:

Ok. Cool.

One other dumb question. I've been setting up my GUI just fine with buttons and background images, however, when I try to add a slider, it doesn't show up. But if I add a pane or panel and then the slider it works. The problem is, I don't want any window appearing behind the slider. In other words I want it just to show over the scene. So my question is, is there a way to just add the slider directly to the JDesktop and have it work or is there a way to make the frame completely invisble? I've looked in serveral places but can't seem to figure this out. I'm sure it's either painfully simple or a bug. XD

hmm, that should work - did you try to repaint() it?

Yes sir I have. I'm doing it in the constructor of a class that I created that extends gamestatenode and gets activated when a user clicks a button. Although I shouldn't think that matters because the other elements, buttons, jlabels work.  :?

Ok. I even tried repainting the JDesktop after the gamestatenode was activated. Still no go.

do you add the slider to a panel first ???

what layout managers are you using

Well if I add it to an additional panel or frame, then it shows up, but so does the panel and I don't want that. So I'm just trying to add directly to the JDesktop.

I'm just using the default layout manager.

does panel.setOpaque(false) help

Nope. Tried that already.:frowning:

To follow up. I guess what you were suggesting was to make the panel invisible. Yeah. I tried several techniques and none seemed to make it go away without also losing the slider.

Ok. It was something really dumb, but something that I wouldn't expect. I wasn't setting the size of the slider (although at one point I thought I had). But setting the size, made it show up. Odd.