Display Emoji character in JTable

懵懂的女人 提交于 2020-01-04 04:37:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/26778769/display-emoji-character-in-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!