Display Emoji character in JTable
I want to map a loudspeaker in JTable
:
@Override
public Object getValueAt(int row, int col)
{
switch (col) {
[...]
case 2:
String symbol = "\uD83D\uDD0A";
return "State " + symbol;
default:
return "";
}
}
Unfortunately, I just see a square box. I'm not sure if I need to set the specific one Font
that supports this character, or apply a different encoding.
For searchers looking for a solution:
I have implemented a CustomRenderer for the JTable like @trashgod. Examples here or here .
source to share
Yes, you will need two things:
-
A font containing the required glyph loaded as shown here .
-
A
TableCellRenderer
in which you can use a font as shown here .
Alternatively, consider TableCellRenderer
one that implements the interface Icon
as shown here . Graphical context techniques fill(Polygon)
and drawArc()
should give satisfactory results.
source to share