JavaFX: How can I display Emoji?

I struggle with this problem a lot and I cannot understand it. I need to somehow display Emoji (like in WhatsApp) in a JavaFX application.

I tried this with awt and Swing, and now I had no success (EDIT: swt works, but probably only for Mac). I tried it with advanced Unicode and Codepoints, but that didn't help. I hope this is even possible, because Windows usually does not allow Emoji to be displayed (I myself use a Mac).

Today I came across this post about Emoji in JavaFX 8 . There, the guy says that he implemented a way to display Emoji in JavaFX by extending the class javafx.scene.text.TextFlow. There is also a link to a small presentation and from the 57th slide upwards it explains a little these so-called objects EmojiFlow. However, I can not find the download!

Thanks to everyone who answered, I struggled with this for so long, maybe this is even impossible.

Here is a small non-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 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);
    }
}
+4
source share
1 answer

There are two ways to do this:

  • take a font that displays emiticons (less recomand)
  • , :

( )

https://bitbucket.org/kogs/javafx-xmpp-client/src/660b12b5c514034ce78e1f653ea265cd74a645c6/src/main/java/de/kogs/xmpp/client/controller/MessageParser.java?at=master

https://bitbucket.org/kogs/javafx-xmpp-client/src/660b12b5c514034ce78e1f653ea265cd74a645c6/src/main/java/de/kogs/xmpp/client/TextParsing/?at=master

:

( ":)", ": P"...), , Imageview TextNode TextFlow

- >

" : P "

  • → TextNode
  • text → TextNode
  • ...
  • : P → ImageView : P
  • to → TextNode
-1

Source: https://habr.com/ru/post/1535095/


All Articles