Chat Bubble library for JavaFX
Add to maven dependency:
<dependency>
<groupId>com.github.heinrichwizardkreuser</groupId>
<artifactId>javafxchatbubbles</artifactId>
<version>1.0.0</version>
</dependency>
Import the relevant classes:
import com.github.heinrichwizardkreuser.javafxchatbubbles.ChatPane;
import com.github.heinrichwizardkreuser.javafxchatbubbles.Chat;
import com.github.heinrichwizardkreuser.javafxchatbubbles.Message;
Create Chat object and add messages to it:
Chat exampleChat = new Chat("Finn"); // we pass our username as an argument
exampleChat.add(new Message("Jake", "Hi there!"));
exampleChat.add(new Message("Finn", "What up, Jake!"));
Create a ChatPane from the chat
ChatPane chatPane = new ChatPane(exampleChat);
Set colors of each user
exampleChat.setColor("Finn", Color.web("#29D0FA")); // Blue
exampleChat.setColor("Jake", Color.web("#FFA519")); // Orange
Add a title for the chat
chatPane.setTitle("Chat with Jake");
Add a listener event for every time the user types in a message in the text field
chatPane.setMessageListener((msg, chat) -> {
System.out.printf("new Message '%s' from '%s' in chat '%s'\n",
msg.content, msg.sender, chat.toString());
});
Add the ChatPane as you would any pane to (for example) a SplitPane
SplitPane splitPane = new SplitPane();
splitPane.getItems().addAll(new Label("something here"), chatPane);