 |
Spicing up your JTabbedPane
Posted by kirillcool on October 27, 2005 at 02:20 AM | Comments (4)
My previous entry showed the way to provide visual indication of frames with changed content. Based on the suggestions from the comments, this behaviour has been also added to JTabbedPane.
Application should set
SubstanceLookAndFeel.WINDOW_MODIFIED client property
on the tabbed pane's Component (if it's JComponent). The value that
corresponds to unsaved state is Boolean.TRUE.
See 67-second AVI movie (1.2 MB) illustrating the technique.
Pulsating loop on JTabbedPane - red theme (animation start):

Pulsating loop on JTabbedPane - orange theme (midway through animation):

Pulsating loop on JTabbedPane - yellow theme (animation flex point):

In addition, the tabs can now have close buttons (like in NetBeans or SWT). Application should set
SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY
client property on either the tabbed pane's Component (if it's JComponent),
JTabbedPane (for all tabs of that pane) or the UIManager
(for all tabbed panes). The value that corresponds to tab with close button
is Boolean.TRUE. In addition, there's rollover effect on enabled tabs (like
on any other control such as buttons or scroll bars).
See 45-second AVI movie (810 KB) illustrating the technique.
Close button on active tab in JTabbedPane - mouse not over close button (includes mouse pointer):

Close button on active tab in JTabbedPane - mouse over close button (includes mouse pointer):

Close button on inactive enabled tab in JTabbedPane - mouse not over tab (includes mouse pointer):

Close button on inactive enabled tab in JTabbedPane - mouse over tab but
not over close button (includes mouse pointer):

Close button on inactive enabled tab in JTabbedPane - mouse over tab and
over close button (includes mouse pointer):

This property
can be set in three ways:
- On JTabbedPane tab component itself (if it's JComponent). If the
property is specified here and it's either Boolean.TRUE or Boolean.FALSE,
its value is taken.
- On JTabbedPane itself. If the property is specified here and it's either
Boolean.TRUE or Boolean.FALSE, its value is taken and is relevant for all
tabs in this JTabbedPane that weren't found in the previous step.
- As global setting in UIManager. If the property is specified here and it's either
Boolean.TRUE or Boolean.FALSE, its value is taken and is relevant for all
tabs in all JTabbedPanes that weren't found in the previous two steps.
Note that the default behaviour (if you do not specify this property anywhere) is
not to use close buttons at all - in order to not interfere with Java 6.0 tabbed
components. For example:
JTabbedPane pane = new JTabbedPane();
JPanel component = new JPanel();
component.putClientProperty(SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY,
Boolean.TRUE);
pane.addTab(component);
JPanel component2 = new JPanel();
// Will not have close button unless the tabbed pane itself specifies
// Boolean.TRUE as value for its client property or UIManager.put is
// called on this property with Boolean.TRUE
pane.addTab(component2);
Once again - the behaviour is not disruptive. If you don't specify this property anywhere, you will not have close buttons on your tabs. This will allow Java 6.0 applications that set custom tab header components to continue working correctly.
As always, you can run a Web Start demo or download the latest Substance 2.1 development drop from here.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Thanks a lot, this article is great, haven't been able to test this yet because of some compilation troubles, but thanks.
Posted by: flex99279 on November 04, 2005 at 06:26 AM
-
and update: figured out the stupid little compilation errors, but when I run a test tabbed pane, it looks just like the conventional jtabbedpane, and i followed your steps. Any suggestions?
Posted by: flex99279 on November 04, 2005 at 10:56 AM
-
Hi,
First of all, you should take the latest drop of version 2.1, and not version 2.0. However, i guess you did that since the client property name was not defined in 2.0. You are welcome to open a defect on 2.1 and attach a simple example of the code that doesn't work as expected. This way we can track and document it.
Posted by: kirillcool on November 04, 2005 at 11:15 AM
-
nice job! ^^
Posted by: bisnit on February 17, 2007 at 04:04 AM
|