Jump to content
  • Advertisement
Sign in to follow this  
Vyper_uk

[java] Swing JTabbedPane MouseListeners

This topic is 4853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm making a simple editor for tile based maps, and I'm using a JTabbedPane with canvas classes in each tab to represent the different layers of my map (eg the bottom layer of tiles only shows if there is nothing on the layers above it etc). What I want to do is add appropriate mouselisteners to the tabbedpane so that I can paint tiles onto the canvases using the mouse. However, mouselisteners added to the JTabbedPane class only seem to work on the selection tabs, and not the things actually in the tabs (my canvases). So from what I can see I have two options. The first is to make a seperate mouse listener for each canvas and bind them to the actual canvases. Would this have a big performance hit (I'm looking at about 4 tabs)? The second is to have one mouselistener and add a ChangeListener to the tabbedpane which removes the mouse listener from the tab which is no longer visible, and then adds it to the one which has become visible. This all seems very messy, is there a better way of doing it? And if not which of these methods is the 'cleanest' and best for performance? Thanks

Share this post


Link to post
Share on other sites
Advertisement
It's not a performance hit to have a bunch of MouseListeners sitting around listening to different things. The great thing about the Listener pattern is that it doesn't actually do anything until its used. Say you have panels A,B,C. A gets a click, the system finds A's listeners, A's listener receives the click. Whether or not B and C have listeners (maybe even the *same* listener) doesn't affect this process at all.

And in the interests of code cleanliness, you don't need to make the MouseListeners seperate objects. Any object can be a MouseListener. And you can use one object to listen to multiple things (as long as your logic won't get confused by this).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!