|
|
||
Kirill Grouchnikov's Blog
«Visual feedback on password strength |
Main
| NetBeans look and feel competition - a low-hanging iPod »
Spicing up your JTabbedPane - part IIPosted by kirillcool on December 22, 2005 at 12:49 PM | Comments (0)This entry describes the capabilities that release 2.1 of Substance look-and-feel provides for your tabbed panes. They are:
The first request was to enhance the listener mechanism on close buttons of tabbed panes. As mentioned in the above blog, you can register any number of listeners that will be called when close button of some tab in some tabbed pane is clicked. The CloseTabListener interface defines the following two methods: /** * Called when a tab is about to be closed. */ public void tabClosing(JTabbedPane tabbedPane, Component tabComponent); /** * Called when a tab is closed. */ public void tabClosed(JTabbedPane tabbedPane, Component tabComponent);There were two separate requests regarding this mechanism:
/** * Called when a tab is about to be closed. Can veto the tab closing. * * @returnAll vetoable listeners that are either registered for the specific tabbed pane, or are registered globally (for all tabbed panes) are called when the close icon is clicked. If at least one of them returns false, the tab will not be closed. Otherwise, the tabClosing and tabClose functions will be called. A simple example is to show the confirmation dialog as:
public void tabClosed(JTabbedPane tabbedPane,
Component tabComponent) {
System.out.println("Closed tab - specific");
}
public void tabClosing(JTabbedPane tabbedPane,
Component tabComponent) {
System.out.println("Closing tab - specific");
}
public boolean vetoTabClosing(JTabbedPane tabbedPane,
Component tabComponent) {
int userCloseAnswer = JOptionPane.showConfirmDialog(
Check.this,
"Are you sure you want to close this tab?",
"Confirm dialog", JOptionPane.YES_NO_OPTION);
return (userCloseAnswer == JOptionPane.NO_OPTION);
}
The following dialog will be shown to the user when the tab close button is clicked:
Note that this extension doesn't break the existing API which is still fully supported and provides the exact same functionality as before. The second request was to provide an option for drawing vertical rotated tabs when the current placement for the tabbed pane is either LEFT or RIGHT. The solutions described elsewhere (by Santosh and Lee Ann) involve a composite icon that simulates the tab and effectively hides the text from the tabbed pane UI delegate (by putting it in the icon and rotating the entire icon). The above solutions work, but involve using third-party classes and changing your code to use these classes. In addition, since Substance provides the close buttons on tabs, they are not easily applicable. Substance provides unintrusive solution for rotated vertical tabs. There are two properties that you can set:
JTabbedPane jtp = new JTabbedPane();
TabNumberedPanel tnp1 = new TabNumberedPanel(jtp, 1);
tnp1.putClientProperty(
SubstanceLookAndFeel.TABBED_PANE_VERTICAL_ORIENTATION_ROTATE_ICONS,
Boolean.TRUE);
jtp.addTab("tab1", SubstanceImageCreator.getThemeIcon(null), tnp1);
jtp.addTab("tab2", SubstanceImageCreator.getThemeIcon(null),
new TabNumberedPanel(jtp, 2));
TabNumberedPanel tnp3 = new TabNumberedPanel(jtp, 3);
tnp3.putClientProperty(
SubstanceLookAndFeel.TABBED_PANE_VERTICAL_ORIENTATION_ROTATE_ICONS,
Boolean.TRUE);
jtp.addTab("tab3", SubstanceImageCreator.getThemeIcon(null), tnp3);
jtp.addTab("tab4", SubstanceImageCreator.getHexaMarker(4,
SubstanceLookAndFeel.getTheme()), new TabNumberedPanel(jtp,
4));
jtp.addTab("tab5", SubstanceImageCreator.getHexaMarker(5,
SubstanceLookAndFeel.getTheme()), new TabNumberedPanel(jtp,
5));
jtp.setEnabledAt(2, false);
jtp.setEnabledAt(3, false);
jtp.putClientProperty(
SubstanceLookAndFeel.TABBED_PANE_VERTICAL_ORIENTATION, true);
Note that you get the desired behaviour by setting a few client properties, which have no effect under other look-and-feels.The only limitation of this technique is for tabs that support arbitrary components (added in Mustang, described in this blog entry by Alexander Potochkin). Such tabs will not be rotated correctly, since these components are not painted using the UI delegates at all. I have discussed this with Alexander and he pointed out additional problem - the need to translate mouse coordinates to allow the tab component to correctly handle the events. The bottom line (at least for Mustang) is - do not use this feature if your application is using the new JTabbedPane functions (which automatically implies that it's running under Mustang). One last thing - if you like Substance, help internationalize it! (small print - eternal glory is not guaranteed :) Starting from version 2.2 (code-named El Paso) the additional UI elements (system menu items, heap status panel, menu search panel) are internationalized. You are welcome to view the list of available translations and send me additional translations to kirillcool [at] yahoo.com. Thanks in advance Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||
|
|