Posted by kirillcool
on November 18, 2006 at 10:34 AM PST
This entry shows how to add preview functionality to your Swing scroll panes.
Previous entries on this blog introduced a few enhancements that were made in Substance look and feel to the scroll panes:
One of the comments requested having a "preview" functionality on the scroll panes. The request outlined having a button in the lower-left / lower-right (depending on the scroll pane orientation). Clicking on a button would bring up a thumbnail of the scroll pane contents allowing to quickly navigate to the relevant section. But wait - it already exists in the JDNC incubator project. So, i contacted the original developer, Pierre Le Lannic, and he graciously agreed to contribute this code to Substance (this was needed since the JDNC license is not BSD compatible). Thanks, Pierre.
Over the course of adopting his code, i've made some changes:
- The control itself is a button that allows rollover effects.
- When you drag the view rectangle, the scroll pane scrolls to that location.
- Dismissing the popup preview (with Escape key) scrolls the viewport to its original location (using the animation layer from laf-widget project).
- The icon itself has been synced with Substance search / preview icons.
- The new
LafWidget.COMPONENT_PREVIEW_PAINTER client property can be used to install custom preview painter on the scroll pane. This allows changing the preview painting, preview popup window size etc.
After all this has been done, Pierre came up with a great idea (wish i thought about this first :) - why not put it in the laf-widget (see this java.net article that describes this project). And indeed - why not? This way it can be available not only to Substance, but to any other third-party look-and-feel. This has been done in the latest development drop of both projects. Once again, many thanks to Pierre for his original contribution and the ideas.
Here is the WebStart link to a test application. Press the overview button, move the mouse over the preview popup, release it or press Escape and see how it feels. Use the
c-preview checkbox to turn on a custom preview painter (note that it produces larger popup and smoother thumbnail):
For those behind corporate firewalls, here are two screenshots. The first one shows a scroll pane with rolled-over scroll pane selector button:
The second one shows the scroll pane selector popup with preview thumbnail: