Chat Client Emoticons Window Java

Chat Client emoticons window JAVA

I suppose you mean a chat window like this sort. In that case, you'll need to learn how to layer components over one another, in this case a jPanel, or a jLayeredPane nested inside the main jFrame.

Chat

How display Label with emojis using Swing JAVA

What other font can I use?

See this answer to get a list of installed fonts which will display all the characters of a String. This should be done at run-time, unless you are supplying a suitable Font with the app.

Notes:

  1. The code will need to use the Unicode character which corresponds to the emoji.
  2. It will be monochrome, same color as the text. Like seen here.

Sample Image

import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.util.*;

public class IHeartNickel {

private JComponent ui = null;
Vector<String> fonts = new Vector<>();
// heavy black heart in Unicode
String heart = new String(Character.toChars(10084));
String msg = "I " + heart + " Nickel (%1s)";

IHeartNickel() {
initUI();
}

public final void initUI() {
if (ui != null) {
return;
}

ui = new JPanel(new BorderLayout(4, 4));
ui.setBorder(new EmptyBorder(4, 4, 4, 4));
String[] allFonts = GraphicsEnvironment.
getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (String f : allFonts) {
Font font = new Font(f, Font.PLAIN, 1);
if (font.canDisplayUpTo(msg) < 0) {
fonts.add(f);
}
}
JList list = new JList(fonts);
list.setVisibleRowCount(10);
list.setCellRenderer(new HeartListCellRenderer());
ui.add(new JScrollPane(list));
}

public JComponent getUI() {
return ui;
}

public static void main(String[] args) {
Runnable r = () -> {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception useDefault) {
}
IHeartNickel o = new IHeartNickel();

JFrame f = new JFrame(o.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);

f.setContentPane(o.getUI());
f.pack();
f.setMinimumSize(f.getSize());

f.setVisible(true);
};
SwingUtilities.invokeLater(r);
}

class HeartListCellRenderer extends DefaultListCellRenderer {

@Override
public Component getListCellRendererComponent(
JList<? extends Object> list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
JLabel l = (JLabel)c;
Font font = new Font(value.toString(), Font.PLAIN, 20);
l.setText(String.format(msg, font.getFontName()));
l.setFont(font);

return l;
}
}
}

Java replace text with emoji

My guess is that the problem is whatever is rendering the emoji for you, not the string of text that you are rendering. In other words, your code is working fine.

I just ran your code like this:

public static void main(String[] args) {
EmojiReplacer test = new EmojiReplacer();
System.out.println(test.replaceString(":) :d >:) :$"));
}

and I get this:

 br>

which looked good both in my IntelliJ output window, and here. I'm on a Mac.

What is taking the String that your code produces, and producing the actual visual emojis for you? Since the browser can obviously render them, have you tried copying the emojis that you think look wrong, and pasting them into your browser, like into your message. The example of a bad emoji you show seems to be a screen shot, not the actual emoji rendered by the browser.

Implementations of Emoji (Emoticon) View/Keyboard Layouts

I found a very useful Emoticon Keyboard. This keyboard is not using Unicode sequences but rather just local image assets. I am thinking that this type of keyboard can only be useful within this app and not with other apps or Operating Systems.

So instead I am replacing the ImageView containing an asset with a TextView containing a Unicode sequence.

After cross referencing Supported Unicode Sequences as well as the Visual Unicode Database I realized that \u1F601 was a 32 bit Unicode representation, and the 16bit representation can be set like :

EditText messageInput = (EditText) findViewById(R.id.message_input);
messageInput.getText().append("\ud83d\ude01");


Related Topics



Leave a reply



Submit