Fork us on GitHub

Pressed/Selected Icon Font & UTF-8

My favorite features are seamless...
Pressed/Selected Icon Font & UTF-8

Pressed/Selected Icon Font & UTF-8

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) or 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.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.