The Source for Java Technology Collaboration
User: Password:



Kirill Grouchnikov

Kirill Grouchnikov's Blog

Spicing up your JTabbedPane - part V

Posted by kirillcool on June 20, 2006 at 01:36 PM | Comments (12)

This is the fifth part of the series that describes the additional capabilities that you can get on your tabbed panes.
  • The first part described close buttons and animation on modified tabs
  • The second part described vetoable close buttons and vertical tabs.
  • The third part described single-click close of multiple tabs and custom alignment of tab texts on left and right placement.
  • The fourth part described hover preview popup and tab overview dialog.
This entry describes the new feature available in the next version of Substance look-and-feel (code-named Grenada) and any other third-party LAF using laf-widget layer.

First, you're welcome to read this blog entry that introduces the notion of widget into the world of look-and-feels. While Substance LAF is currently the only LAF supporting the "feel" widgets, the approach has been successfuly tested on six other third-party LAFs (Squareness, Pagosoft, Looks, Liquid, Infonode and Napkin. While the previous four parts described Substance-specific features, the introduction of laf-widget now allows additional third-party LAFs to provide tab overview dialog and tab hover preview.

The new addition to laf-widget layer provides the functionality of Ctrl Tab Firefox plugin. Once you install that plugin, pressing Ctrl+Tab opens three windows, one in the middle that shows a large thumbnail of a tab (starts from the current tab), and two side windows displaying small thumbnails of previous and next tabs. Each press on Tab key (while Ctrl is pressed) moves the thumbnails forward (cycling). Once Ctrl is released, the currently shown tab (in the middle thumbnail window) is selected.

For those of you who don't know, Swing already provides keyboard accelerators for switching the tabs. These are Ctrl+Page Up for moving forward and Ctrl+Page Down for moving backward. Two major disadvantages are:
  • The selection actually changes (which may trigger some application event handlers - may be undesirable if the user just wants to see the tab preview).
  • It only works in the current tab run.
The newly added (quite small ~10K) widget in laf-widget project (and subsequently in the new version of Substance) provides the Ctrl+Right Arrow and Ctrl+Left Arrow keyboard shortcuts that provide thumbnail paging of all tabs in the currently focused tabbed pane (Ctrl+Tab can not be taken since Tab event is already consumed by Swing for the focus transfer). Here is a screenshot to illustrate (click to see the full size):


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • "paging of all tabs in the currently focused tabbed pane", does this mean the focus must be on a tab itself or in any component within the currently selected tab? If the latter, what happens when the focus is in a text field (Ctrl+Left/Right jumps between words)?

    Posted by: gfx on June 20, 2006 at 05:14 PM

  • Romain,

    That would be the input map corresponding to JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT - so it's any component within the currently selected tab. For your second question - if that component consumes the relevant event (like the text fields do), it's not passed up the chain to the tabbed pane (no switching is done).

    Posted by: kirillcool on June 20, 2006 at 05:23 PM

  • hi,
    this UI is great, it gives a lot to my java apps ;)

    i would like to know if it is possible to make these two things (sorry if it is easy, at the time i take my time to make my application, the better graphics are not the priority, so i don't take a lot of time to search for wath i request now, sorry)

    1: making a jtabbedPane's background color blink(or other fun animation) to say user something new is in the tab (text changed for exemple) . I could select the tab, but it's not wath i want :(

    2: making only the close buttom on some tabs, and not all.

    Once again, sorry if i request easy stuff. And sorry for my bad english, i'm french

    Can you (or a reader) help me?

    Thanks a lot ;)

    Posted by: alain57 on July 24, 2006 at 04:13 PM

  • 1. In version 3.0, there is a new animation capability on tab icons (hadn't blogged about it yet). Download the test application, go to "Tabbed Pane", select a tab in "Single tab controls" panel, choose one of Load / Error / Warning animation and Click "Set Animation". You will see that the icon of the corresponding tab is animated. This can be easily extended to other types of animations (for icon only). However, i'd recommend reading this entry which is linked as the first part on tabbed pane. There you can see an easy way to specify a "modified" animation on a tab. This can be turned off when that tab is selected.
    2. The same link as above - the close property can be specified on a specific tab component, the whole tabbed pane or globally. The test application specifies that close icon shouldn't appear on every tenth tab (by setting the relevant property to Boolean.FALSE).

    Posted by: kirillcool on July 24, 2006 at 04:24 PM

  • thank you very much for so fast answering, i will try what you say .

    Posted by: alain57 on July 24, 2006 at 10:52 PM

  • i finaly did it.
    for the close bouttom it's really simple.
    for the blink effect also, even if i had problem finding the good proprerty (WINDOW_MODIFIED)
    now the last nooby questions :
    is there a way to make the red, orange, yellow animation a bit faster ?
    because the red color take too much time ...
    is there a way to change the 3 colors ?
    yes i know it is posible by modifying the sources, but is there a function that do that ?

    Once again thanks a lot, this really give life to my application ;)

    Posted by: alain57 on July 25, 2006 at 01:10 AM

  • The animation duration is long by design - so as not to distract too much from the modified tabs. The colors are hard-coded by design to provide consistent animation sequence and convey the sense of "don't close it without thinking about it".
    Perhaps in your case it's better to set the animation on the icon only? It is a 1-second loop - see the test application as described in my answer from yesterday.

    Posted by: kirillcool on July 25, 2006 at 04:08 PM

  • well, i think i sould ask your mail for not having 500 comments lool but i prefere comments so other peaple can learn too ;)

    in fact, i was originaly search for a way to make a tab blink.
    but your pulse system is way much better.

    i don't want to change an icon or animate an icon, but really to change the tab color and animate it.

    I juste change the TabPulseTracker.java file for having a pulsating system with red color beeing not to long.
    it was really simple in fact, i just change the two -80 with -20

    for the time i did not found the color, but the red/yellow is a choice i could had make by myself, so i'm not really searching.

    Other fun idea would be to make a function who decrease the timer and then increase it again at each round,
    so animation will go to slow to ultra fast and from utlra fast to slow...

    Posted by: alain57 on July 26, 2006 at 05:49 AM

  • OK, so it's been a while ;-).

    Control PageUp/PageDown is only moving the tab traversal hint for me (or whatever you call that light outline around the component that moves with TAB). The tabs are not getting selected (brought to the front) until I type SPACE. I'd prefer that Control PageUp/PageDown actually select the tab as well (which your article implies).

    Do you have any thoughts why this isn't working for me? I'm using Java 6.

    Posted by: wohler on February 01, 2007 at 03:24 PM

  • wohler,
    For the Ctrl PageUp / PageDown you'll have to ask in Swing-related forums, since this is core Swing functionality.

    Posted by: kirillcool on February 01, 2007 at 03:30 PM

  • OK, any suggestions?

    --Bill

    Posted by: wohler on February 01, 2007 at 03:36 PM

  • Never mind, I found them!

    Posted by: wohler on February 01, 2007 at 03:37 PM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds