TileMap with swing (Java)
i'm looking for this effect, but PulpCore doen't works with swing. Do you know what library use, or how to开发者_开发问答 make a TileMap? Also, I'd like to move forever in it.
Thanks.
I'm guessing you don't want to use an actual world-map implementation like JXMapViewer...
The basic functionality appears to be: click on some coordinates, and that point becomes centered in the viewport. One fairly simple way to do this is to have the component(s) that you want to view all contained within a JPanel
and have that panel inside a JScrollPane
with its scrollbars turned off (setHorizontalScrollbarPolicy(HORIZONTAL_SCROLLBAR_NEVER)
and so on). Then, set up a click or action listener for your elements that calculates the new center point, what the new viewport rectangle coordinates will be, and use scrollRectToVisible
on the panel to shift the view. For animation, you can use a Swing Timer
to set up a series of incremental scrolls in the required direction until you reach the target.
精彩评论