Branding Project action icons

I came across a weird bug when trying to brand the various project action icons in the first full Praxis release (yes, I know that was in January – busy year so far – but I’m writing it up now! 🙂 )

Here you can see the problem. Notice the branding works for the icons in the toolbar, but not for the icons in the menu!

What’s that all about?

Well, I eventually tracked down the cause.  It seems that the various Project actions set a non-localized icon as the SMALL_ICON attribute, as well as setting the iconBase attribute.  The different behaviour between menu and toolbar is caused by the code used in Actions.connect(..). ButtonBridge prioritizes the iconBase attribute, so the icon is branded, whereas MenuBridge prioritizes SMALL_ICON.

It seems to be a bug that Actions.connect(..) works differently for menus and toolbars, and probably also a bug that Project actions set a non-localized icon in the first place.

So, workaround?

The workaround I’m using currently in Praxis is to register an Actions.ButtonActionConnector implementation which removes the SMALL_ICON attribute if an iconBase value has been set.

public class MenuIconFixer implements Actions.ButtonActionConnector {

   public boolean connect(AbstractButton button, Action action) {
       return false;

   public boolean connect(JMenuItem item, Action action, boolean popup) {
       Object icon = action.getValue(Action.SMALL_ICON);
       Object base = action.getValue("iconBase");
       if (base instanceof String) {
           if (icon != null) {
               action.putValue(Action.SMALL_ICON, null);
       return false;

The result …


PS. Reported as bug 210973


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s