Jump to content
  • Advertisement
Sign in to follow this  
RobAU78

[java] JComponents on Zoomable Map

This topic is 3971 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

Hey everyone, Right now I'm working on making a zoomable map for use in strategy games. I am able to zoom in and out successfully. However, I am having trouble using mouse events with JComponents built into the map. I would like to use the built-in behavior for mouse-entered and mouse-exited events to highlight and de-highlight the JComponents. My problem is that there seems to be no obvious way to pre-translate the mouse coordinates to compensate for the current zoom factor. Regardless of the zoom factor, mouse-entered and mouse-exited events are dispatched when the mouse pointer is in the original bounds of the JComponent. Does anyone know the origin of mouse-entered and mouse-exited events in Swing? Are they created within Java or do they come from the native OS? Also, is there any easy way to "forward" mouse events from one component to another? Would it be easier to roll my own classes for selectable map components? Thanks in advance for your responses. :) - Rob

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty sure that any and all input events would have to originate from the OS. However, I believe in Swing that it's Java and not the OS who decides if a JComponent is the target of an event. Swing is lightweight, so there aren't any native peers to tell Java anything.
Some of the components have protected methods on them like processKeyEvent() and processMouseMotionEvent(). You can always subclass the JComponent and override these methods as public. However, make sure that the default behavior is called as well (through super.processMouseMotionEvent()).
I haven't tried anything like that above, but I'm sure it's been done before with custom drawn components.

Share this post


Link to post
Share on other sites
Don't you "zoom" the map JComponents too though?

I've just finished doing exactly the same as you, but I increase or decrease the size of any present JComponents on the map (setBounds), so as I zoom in, my (e.g.) JLabels increase in size, zoom out, they decrease.

I've no problems with mouse entering/exiting detection...

Or perhaps I'm misunderstanding you...

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!