Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX: How can I display Emoji?

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);
    }
}
like image 794
Kametrixom Avatar asked Apr 04 '14 20:04

Kametrixom


People also ask

Can I use emojis in JavaFX applications?

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?

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.

What are emojis in HTML?

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.

What is emoji-Java and how to get it?

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.


1 Answers

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:

  1. openmoji
  2. twemoji
  3. emojitwo

You can even compile this library with your own emoji pack. The instructions how to do so are in README.md

like image 162
user14023280 Avatar answered Oct 12 '22 07:10

user14023280