Consumer<Graphics2D> (float x, float y, int startOffset, int endOffset) { return g -> { g.setFont(getFont()); g.drawString(myCode, x, y); // draw brackets around the character code float xEnd = x + myWidth - 1; float yTop = y - Math.min(myView.getAscent(), myView.getCapHeight() + BRACKETS_DISTANCE_TO_TEXT); float yBottom = y + Math.min(myView.getDescent(), BRACKETS_DISTANCE_TO_TEXT) - 1; LinePainter2D.paint(g, x, yTop, xEnd, yTop, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); LinePainter2D.paint(g, x, yTop + BRACKETS_SIZE, x, yTop, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); LinePainter2D.paint(g, xEnd, yTop + BRACKETS_SIZE, xEnd, yTop, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); LinePainter2D.paint(g, x, yBottom, xEnd, yBottom, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); LinePainter2D.paint(g, x, yBottom - BRACKETS_SIZE, x, yBottom, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); LinePainter2D.paint(g, xEnd, yBottom - BRACKETS_SIZE, xEnd, yBottom, LinePainter2D.StrokeType.INSIDE, BRACKETS_THICKNESS); }; }