Open Source & Free  

Pressed/Selected Icon Font & UTF-8

Pressed/Selected Icon Font & UTF-8

Header Image

One of our support emails drew my attention to a glaring ommission in our icon font support…​
When we create an icon for a Button it’s color matches the unselected color of the button which might not
look as attractive when the Buton is selected or pressed!

The thing is that with an icon font this is trivial to accomplish and requires literally no code changes. So starting with
the the next update calling
FontImage.setMaterialIcon(Label l, char icon)
FontImage.setMaterialIcon(Label l, char icon, float size)
with a Button will implicitly set the pressed/selected & disabled icons for the button.


Form f = new Form("Buttons", BoxLayout.y());

CheckBox pressed = CheckBox.createToggle("Pressed");
FontImage.setMaterialIcon(pressed, FontImage.MATERIAL_THUMB_UP, 5);
Button unselected = CheckBox.createToggle("Unselected");
FontImage.setMaterialIcon(unselected, FontImage.MATERIAL_THUMB_UP, 5);
Button disabled = CheckBox.createToggle("Disabled");
FontImage.setMaterialIcon(disabled, FontImage.MATERIAL_THUMB_UP, 5);


PSA – Always Use UTF-8

Everyone has their “pet peeve” about Java and mine is the encoding support. In a typical Sun way the Java API
chose the wrong defaults aligning itself with the system instead of aligning itself with whats right.

UTF-8 works for pretty much everyone and using it universally would solve many of the problems we see frequently.
However, Java defaults to platform native encoding and so minor mistakes like calling the String.getBytes() method
can be devastating and hard to track. To make matters even more annoying the correct method String.getBytes(encoding)
throws a checked exception for no real reason making it far more painful to use than the default…​

I was reminded of this just the other day, it seems our Properties
class used ISO-8859-1 encoding. This is pretty much the most standard encoding and should be supported everywhere…​

Turns out it doesn’t work in the JavaScript port which uses UTF-8. Since UTF-8 makes more sense we just fixed the
Properties instead of fixing the encoding which is apparently challenging.


  • Chibuike Mba says:

    Hi Shai, does Toolbar Command support this button icon capability?

  • Shai Almog says:

    No & sort of…

    This is a bit problematic. Commands support the pressed/selected/disabled icon styles but since you don’t normally call the set icon method on them thru the FontImage class this won’t work well…

    We’ll add to the next update a version of setMaterialIcon that accepts a command and UIID. And we’ll also try to add a few methods to toolbar that should do effectively this e.g. addMaterialCommandToSideMenu(…)

  • Chibuike Mba says:

    OK. Great. Will be looking forward for that.

Leave a Reply