Skip to main content

SwingX: JXScrollMap

Posted by kschaefe on September 22, 2010 at 12:54 PM PDT

I mentioned during my BOF at JavaOne a new component that is close to ready for moving into SwingX: JXScrollMap.

Part of the way that SwingX works is that members first join the incubator project. Members contribute ideas to the incubator, flesh them out, and eventually bring them into SwingX. The incubator contains lots of stuff from really mature ideas to things that aren't. Some of the ideas have moved into SwingX, but a number of good ideas still reside there.

As SwingX was preparing for version 1.0, we placed a ban on any component additions, as we needed to concentrate on the issues at hand. The first goal post-1.0 was to remove SwingX sorting and filtering migrating JXTable and JXList to core sorting and filtering. During this time we also identified a few components that we thought might make good additions to SwingX proper. One such component was the ScrollPaneSelector.

ScrollPaneSelector is a popup that displays a mini-map of the viewport contents. Users move the viewport rectangle on the mini-map to place the viewport rectangle in the scroll pane. ScrollPaneSelector was definitely an idea that we liked. Recently, I took the ScrollPaneSelector code and made a clean up pass. I separated the control logic into the UI delegate, fine-tuned the API, and renamed it. Without further ado, I'd like to present JXScrollMap. Neither the name nor the API are finalized, as the component is still in the incubator, so any feedback is welcomed. As a side note, my second choice for naming it was JXScrollView, but I thought people might confuse it with the viewport.

JXScollMap embarks on some new territory for SwingX. Part of the original design that I liked so much was the use of Robot to automove the user's mouse to the location of the current viewport when the mini-map is displayed. Since Robot is secure, this presents an additional challenge. SwingX should run without breaking sandbox containment; no signing should be necessary. So, we need to decide how JXScrollMap is going to run without Robot. I expect that we will simply do nothing in insecure environments, meaning the current highlight will be placed, but the mouse will remain unchanged. That question is still up in the air and is one reason the component still resides in the incubator. JXScrollMap now has a property is/setSynchronizedScrolling, which determines whether the viewport location updates when the mini-map rectangle changes. It is recommended to turn this off when running in a secure environment where Robot does not work, since the user's first movement may be to place the mouse into the popup.

So, without further ado, JXScrollMap (signed) to show full functionality:

Related Topics >>


technical discussion at

technical discussion at SwingLabs forum:


Cheers, Jeanette


Why mouse cursor at all?

Very nice component/idea! I've made similar components, but placing it in the scroll bar area with popup map is clever. I think the button should show even if there is only horizontal or vertical srcoll bars though (which probably means reinventing JScrollPane).

Anyway.. Why do show the mouse at all when the map pops up? Isn't the highlight rectangle "cursor" enough? You only need a visible mouse cursor when exiting the map popup (or don't allow that to happen). Then, the only thing you'll miss is the repositioning of the cursor on mouse release (which I'm not sure if I like in the first place).

Keep up the good work!

Good idea!

You're right there is no need to have a mouse at all.  You don't need to have a visible hotspot, the rectangle should be enough.

Now we need to add good cursor support to SwingX. ;)


good work :-) As to the Robot

good work :-) As to the Robot usage: I think we should do the same as the original version in the incubator (contributed by weebib) - in secured environments bring the mountain to the mouse (as steve already suggested)

Cheers, Jeanette



API review soon

Yeah, I wanted to get a variety of optional ideas for the insecure environment before settling on one.  Currently, it does not move the mouse at all, which is what weebib did.  My first thought was to use MouseInfo.getPointerInfo(), but it too is secure.  A previous comment suggests moving the window to center on the mouse.  There may be others.  A couple more tweaks and I think it is time to put the API out for review.  Or perhaps to put it out for review and tweak after?


there's a

there's a component.getMousePosition() which is secure to call.

BTW, we should move the technical discussion over to the SwingX forum. And yeah, go publish and tweak afterwards :-)

CU, Jeanette



That is slick

I really like that.  Nice work!

Bring the mountain to the mouse

Very nice, one thing sprang to mind, is that if you can't move the mouse without signing the jar you could move the minimap so that the mouse in it's current position is located in the correct region of the minimap.