4

I want to display loudspeaker character in a JTable:

    @Override
    public Object getValueAt(int row, int col)
    {
        switch (col) {
            [...]
            case 2:
                String symbol = "\uD83D\uDD0A";
                return "State " + symbol;
            default:
                return "";
        }
    }

Unfortunaly i just see an square box. I'm not sure if i have to set an specific Font supporting this character or to apply an other encoding.

For Googlers looking for a solution:
I implemented a CustomRenderer for the JTable like @trashgod sugested. Examples are available here or here.

Community
  • 1
  • 1
alex
  • 5,516
  • 2
  • 36
  • 60
  • 1
    If you're not sure of the character encoding, check out [emoji-java](https://github.com./vdurmont/emoji-java) which contains the right unicode value for every emoji. – Vincent Durmont Nov 06 '14 at 18:49
  • I tried emoji-java, but it just helps to ease the use of such characters but it doesn't help to solve the font problem. Finally i suceeded with @trashgod sugestion of implementing the TableCellRenderer to view icons – alex Nov 10 '14 at 08:20
  • I can't display emoij in a JTable cell. it doesn't work. I have a renderer setup and I'm using Vincent's emoij-java. Inside the renderer, I already have setText(EmojiParser.parseToUnicode(value.toString())) where value is the object--it was a StringBuffer, that's why I need toString(). What's missing this? – mk7 Oct 23 '15 at 20:00

1 Answers1

2

Yes, you'll need two things:

  • A font containing the required glyph, loaded as shown here.

  • A TableCellRenderer in which to use the font, as shown here.

Alternatively, consider a TableCellRenderer that implements the Icon interface, as shown here. The graphics context's fill(Polygon) and drawArc() methods should produce a satisfactory result.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • OK, thank you. I solved the problem by using TableCellRenderer to display the icons as you suggested! – alex Nov 10 '14 at 08:19