I've been struggling with this problem a lot now and I can't seem to figure it out. I need some way of displaying Emoji's (as in WhatsApp) in a JavaFX Application.
I tried it with awt and Swing and I haven't had any success now (EDIT: swt works but probably just for Mac's) I tried it with extended Unicode and Codepoints but this didn't help. I hope it's even possible, because Windows usually doesn't let you display Emoji's (I myself use a Mac).
Today I stumbled over this post about Emoji's in JavaFX 8. There a guy says he has implemented a way of displaying Emoji's in JavaFX by extending the javafx.scene.text.TextFlow
class. There is also a link to a little presentation and from the 57th slide upwards it explains these so called EmojiFlow
objects a little.
However I can't seem to find a download!
Thanks to everyone answering, I've been struggling so long with this one, maybe it even is impossible
Here is a little not working example:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
VBox root = new VBox();
// I used TextFlow here because the article suggested
// extending this class, but I know it's not working
// just like this
TextFlow textFlow = new TextFlow(new Text("Should be alien smiley: "
+ (char) 0xF47D));
// casting a hex number to a char is equal to using "\uF47D"
root.getChildren().add(textFlow);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
One open source font that supports emojis is OpenSansEmoji. The font can be found at github. Once you downloaded the font you can define it for your textfield as described in an earlier post: Once this is done we can use emojis in JavaFX applications - but only on windows without problems.
How to display an image in JavaFX? The javafx.scene.image.Image class is used to load an image into a JavaFX application. This supports BMP, GIF, JPEG, and, PNG formats. JavaFX provides a class named javafx.scene.image.ImageView is a node that is used to display, the loaded image.
Emojis look like images, or icons, but they are not. They are letters (characters) from the UTF-8 (Unicode) character set. UTF-8 covers almost all of the characters and symbols in the world. To display an HTML page correctly, a web browser must know the character set used in the page.
emoji-java is a lightweight java library that helps you use Emojis in your java applications. How to get it? You can also download the project, build it with mvn clean install and add the generated jar to your buildpath.
There is a project on github pavlobu/emoji-text-flow-javafx it is a library for JavaFX the main purpose of which is to allow users to use extended TextFlow to display emojis. It helps to display consistent emoji images on different platforms where JavaFX application runs.
I had developed it to solve the problem of consistent cross-platform emoji displaying in JavaFX based UI applications. It also helps you to use different emoji images packs, you just need to download .jar with emoji pack that you want to use. Here is a link
Currently it is packed with one of these emoji style packs:
You can even compile this library with your own emoji pack. The instructions how to do so are in README.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With