Visual Paradigm and JTabbedPane on mac os x

I think most of my readers are Polish, so I used to write in polish. But this time I want to forward this information to Visual Paradigm support team, and maybe other english speaking people will find it useful.

Polish readers can skip this article freely, because it is similar to previous ones (JTabbedPane na ligolu (max os x) and JTabbedPane na ogryzku). There is only one difference - this time I'll tune Visual Paradigm's software - the best UML tool I have ever used Happy

I am talking about the issue with java JTabbedPane and how it looks in mac os x with Aqua Look&Feel. The problem lies in tabs in JTabbedPane class theme. It looks very nice, but only one line of tabs is available. In classic metal L&F this is an option, available on developer's request, but - most common - they are put in several lines, to show all tabs possible. It takes more space, but is more convenient.
Let the following screenshots speak for themselves.

The first one is the original Aqua L&F used to edit properties of start event in BP-VA. There are three tabs visible:
General, Assignments and Categories. The list shown on the right is the result of mouse click&hold on the right arrow. It allows the access to the rest available tabs and to choose the one you want to switch to.


The following is the same window, but with the Aqua L&F JTabbedPane changed to metal theme:

The tab's background can be customized too, but that's an application setting, so it looks the same on metal theme (at least in mac os x).

If you want to see more screenshots, especially with vertical layout (which in fact is even worse) please look into
JTabbedPane na ligolu (max os x). Text is in polish, but images are straight forward Happy and show the problem with developer's tool - IntelliJ IDEA (previous to version 8).

Anyway, what's the most important such change can be made by ANYONE. It requires NO developer skills, tools nor other high-qualifications Happy
All you need is to put one jar file into app's lib directory and make a couple of changes in application plist file. I'll explain you how to do that, but first I want to cover why it works and why it is safe, why there is no hack or so.

Java L&F contains a few properties which specify the exact component look. The most important is
swing.defaultlaf. It allows you to specify the class which defines the LookAndFeel. Because I like the Aqua theme I want to change the tabs L&F only. If you have an access to application code the simplest way is to put the following lines into your startup class (and it even doesn't require to the defining all properties, just modification to existing ones):

final String lcOSName = System.getProperty("").toLowerCase();
final boolean MAC_OS_X = lcOSName.startsWith("mac os x");
if (MAC_OS_X) {
System.out.println("MAC OS detected (" + lcOSName
+ "), setting extra UIManager resources for TabbedPane");
UIManager.put("TabbedPaneUI", "javax.swing.plaf.metal.MetalTabbedPaneUI");
UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(2, 2, 2, 1));
UIManager.put("TabbedPane.tabsOpaque", Boolean.TRUE);
UIManager.put("TabbedPane.darkShadow", new Color(122, 138, 153));
//UIManager.put("TabbedPane.background", new Color(184,207,229));
UIManager.put("TabbedPane.selectHighlight", new Color(255, 255, 255));
//UIManager.put("TabbedPane.foreground", new Color(51,51,51));
UIManager.put("TabbedPane.textIconGap", 4);
UIManager.put("TabbedPane.highlight", new Color(255, 255, 255));
UIManager.put("TabbedPane.unselectedBackground", new Color(238, 238, 238));
UIManager.put("TabbedPane.tabRunOverlay", 2);
UIManager.put("TabbedPane.light", new Color(238, 238, 238));
UIManager.put("TabbedPane.tabsOverlapBorder", Boolean.FALSE);
UIManager.put("TabbedPane.selected", new Color(200, 221, 242));
UIManager.put("TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3));
UIManager.put("TabbedPane.contentAreaColor", new Color(220, 221, 242));
UIManager.put("TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6));
UIManager.put("TabbedPane.contentOpaque", Boolean.TRUE);
UIManager.put("TabbedPane.focus", new Color(99, 130, 191));
UIManager.put("TabbedPane.tabAreaBackground", new Color(218, 218, 218));
UIManager.put("TabbedPane.shadow", new Color(184, 207, 229));
UIManager.put("TabbedPane.tabInsets", new Insets(0, 9, 1, 9));
UIManager.put("TabbedPane.borderHightlightColor", new Color(99, 130, 191));

But, what if you are just a user? Well, in such case you have to use the
swing.defaultlaf property. Additionally, you have to add the jar archive with class extending apple.laf.AquaLookAndFeel that contains the code above. I've prepared such class and packed it into archive: LookAndFeel.jar. The rest is very simple.

1. Put the above LookAndFeel.jar into app's lib. In case of Business Process Visual Architect its just
lib directory. The same is if you use the whole "VP Suite x.x". There is a folder named lib, next to bin. Just put the jar file there.

2. Change the classpath of your application to find the new library and specify the java property.
Mac os x's applications are packages, shown by system as a simple application file. Just right click on your application and choose "
Show package contents" from the context menu. Next find the Contents folder with file you are looking for: Info.plist. Double click it to open in Property List Editor system application.
Now you have to make these two changes, both shown on the screenshot below:


Look carefully at the highlighted area. You have to add new property with key "swing.defaultlaf" and value "com.zgibek.mac.LookAndFeel" (that's the class name I put into jar file).
Then you have to add the new jar into classpath as shown above (add "
$APP_PACKAGE/../../lib/LookAndFeel.jar:" at the beginning).

I hope you find it easy to do it yourself. Good luck!

If you are curious how LookAndFeel class is exactly defined, just compile it yourself and play a little with settings, please feel free to download it:
For more information look at Sun (well, Oracle) documentation:
How to Set the Look and Feel.
blog comments powered by Disqus