1. Introduction
Ikonli provides icon packs that can be used in Java applications. Currently Swing and JavaFX UI toolkits are supported.
2. Usage
2.1. Swing
The ikonli-swing:2.4.0
JAR provides a new Icon class: org.kordamp.ikonli.swing.FontIcon
.
You may use this class with any Swing component that supports an Icon property.
2.1.1. Installing
repositories {
jcenter()
}
dependencies {
compile 'org.kordamp.ikonli:ikonli-swing:2.4.0'
}
<dependencies>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-swing</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
2.2. JavaFX
The ikonli-javafx:2.4.0
JAR provides a new Node class: org.kordamp.ikonli.javafx.FontIcon
.
You may use this class with any JavaFX control that accepts a graphic property. You may also use the icon directly as
it is a subclass of javafx.scene.text.Text
. The icon class can be used inside an FXML file too.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import org.kordamp.ikonli.javafx.FontIcon?>
<GridPane prefHeight="60.0" prefWidth="200.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.example.AppController">
<Button GridPane.columnIndex="0" GridPane.rowIndex="0"
mnemonicParsing="false"
prefWidth="200.0">
<graphic>
<FontIcon iconLiteral="di-java" iconSize="64"/>
</graphic>
</Button>
</GridPane>
The iconLiteral
property accepts any of these formats
-
icon-code
-
icon-code:icon-size
-
icon-code:icon-size:icon-color
where the following rules apply
- icon-code
-
An icon code literal such as
di-java
. - icon-size
-
A number (in pixels) specifying the width of the icon.
- icon-color
-
A
javafx.scene.paint.Color
,javafx.scene.paint.LinearGradient
, orjavafx.scene.paint.RadialGradient
literal.
di-java
di-java:32
di-java:64:BLUE
org.kordamp.ikonli.javafx.FontIcon
exposes properties that can be styled using CSS. It defines a node class named ikonli-font-icon
.
-fx-icon-code |
An icon literal such as |
-fx-icon-size |
The size of the icon, in pixels. |
-fx-icon-color |
A JavaFX |
A stackable version is also available, org.kordamp.ikonli.javafx.StackedFontIcon
. This is an specialized version of javafx.scene.layout.StackPane
that accepts instances of org.kordamp.ikonli.javafx.FontIcon
as child content. You may use this class with FXML, like it’s shown
in the following example
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.GridPane?>
<?import org.kordamp.ikonli.javafx.FontIcon?>
<?import org.kordamp.ikonli.javafx.StackedFontIcon?>
<GridPane prefHeight="60.0" prefWidth="200.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.example.AppController">
<StackedFontIcon GridPane.columnIndex="0" GridPane.rowIndex="0" iconSize="48">
<FontIcon iconLiteral="fa-circle-thin" iconColor="red"/>
<FontIcon iconLiteral="fa-camera" StackedFontIcon.iconSize="0.5"/>
</StackedFontIcon>
</GridPane>
org.kordamp.ikonli.javafx.StackedFontIcon
exposes properties that can be styled using CSS. It defines a node class named stacked-ikonli-font-icon
.
-fx-icon-size |
The size of the icon, in pixels. |
-fx-icon-color |
A JavaFX |
2.2.1. Installing
repositories {
jcenter()
}
dependencies {
compile 'org.kordamp.ikonli:ikonli-javafx:2.4.0'
}
<dependencies>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>