Puts icons on JavaFX controls without the usual ceremony. One static call takes a control and an icon name and does the rest: loading the image, resizing it, recoloring it, and keeping the result in a cache so the same icon isn't decoded twice.
IconUtils.setIcon(saveButton, "save"); IconUtils.setIcon(deleteButton, "delete", Color.RED); IconUtils.setIcon(settingsButton, "settings", 32);
Icons are loaded by name from resources/assets/icons. That path is fixed at the moment.
The library isn't published to Maven Central. Two ways to get it:
Download javafx-iconutils-1.0.1.jar from the
releases page and put it on your
classpath.
Or build it and install it into your local repository:
mvn clean install # Maven ./gradlew publishToMavenLocal # Gradle
then depend on io.github.IovAnto:javafx-iconutils.
Requires JavaFX 17.
Setting an icon, on a Labeled (Button, Label, ...) or on a MenuItem:
setIcon(node, iconName) setIcon(node, iconName, double size) setIcon(node, iconName, Color color) setIcon(node, iconName, double width, double height, Color color)
Changing one that's already there — Labeled only:
changeIconColor(node, color) changeIconSize(node, width, height) changeIconColorAndSize(node, width, height, color) removeColorEffect(node)
Cache:
preloadIcons("save", "delete", "settings") // returns how many loaded clearCache() getCacheSize()
Recoloring works through a JavaFX blend mode, so it suits flat single-color icons and leaves photographs alone.
mvn clean test package # or: ./gradlew build test
Tests cover the cache, the loader's failure paths, and configuration.
MIT