Skip to main content

About Plastic Look and Feel

Posted by gfx on July 24, 2005 at 12:12 AM PDT

The Plastic look and feel family is very well known and widely used among Java community. That said I am often disappointed to see some programmers plug it into their UI without taking a look at the available options. Let's take a look at a sample, rather bad looking Swing application:

Plastic

"Yiech!" And you're right. One way to fix this UI is to change the look and feel. Now, it has many other issues, like colors and icons, but we won't bother about this today. I know Plastic looks great and I also know a lot of people like. Best of all it's free and open source, so why not use it? Here we go:

PlasticLookAndFeel laf = new PlasticXPLookAndFeel();
PlasticLookAndFeel.setMyCurrentTheme(new ExperienceBlue());
UIManager.setLookAndFeel(laf);

Note I chose a theme for the look and feel because, after all, I really do care about the result:

Plastic

Ah much better, isn't it? Many programmers would just stop here and go back to more interesting stuff. Yet we can go a bit further with three extra lines of code:

getToolBar().putClientProperty("JToolBar.isRollover",
                               Boolean.TRUE);
getToolBar().putClientProperty(Options.HEADER_STYLE_KEY,
                               HeaderStyle.BOTH);
getJMenuBar().putClientProperty(Options.HEADER_STYLE_KEY,
                                HeaderStyle.BOTH);

As a result, Plastic applies a different style to both the menu bar and the tool bar, giving them a nice, modern rounded look:

Plastic

I also use Swing's JToolBar.isRollover property to hide buttons borders. Even if the result is better looking, both bars show unecessary borders which clutter the screen, mainly on the left and right of the frame. I'll let you get rid of them as an exercise :) And we can go even further by adding drop shadows to popup menus:

Options.setPopupDropShadowEnabled(true);

Those menus integrate nicely with Windows XP:

Plastic

Finally you might not like tabs look. The last feature of Plastic I'm about to use let you give tabs an Eclipse look:

tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY,
                             Boolean.TRUE);

The only problem is that selected tab is a bit difficult to spot when there are many tabs:

Plastic

Take a look at PlasticLookAndFeel and Options classes and try all the options. You might find nice things for your UI :)

Related Topics >>