Reputation: 14973
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);
}
}
Upvotes: 10
Views: 8470
Reputation: 34
Follow these steps to add Emoji as a text:
head to https://apps.timwhitlock.info/emoji/tables/unicode Search for any emoji you want and check its byte code (eg. \xF0\x9F\x98\x81)
create a byte array and add byte code to it eg. I am using this emoji: 😁 and Its byte code is \xF0\x9F\x98\x81 so,
byte[] emojiByteCode = new byte[]{(byte)0xF0, (byte)0x9F, (byte)0x98, (byte)0x81};
String emoji = new String(emojiByteCode, Charset.forName("UTF-8"));
Upvotes: -2
Reputation: 99
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
Upvotes: 3
Reputation: 1768
There are two ways to do that:
(I only did it so far for hyperlinks)
and
Simpler said:
Lookup the text for emoticons (":)",":P"...) and if you found one add a Imageview to the textflow and if not add a TextNode to the TextFlow
-->
"This text is passed :P to the parser"
Upvotes: -2