@Override
  protected void paintComponent(Graphics graphics)
  {
    super.paintComponent(graphics);
    Graphics2D g = (Graphics2D) graphics.create();

    Dimension size = getSize();
    int topY = verticalGap;
    int bottomY = size.height - verticalGap;
    int barX = horizontalGap;
    int tickX = horizontalGap+barWidth+tickWidth;

    // Draw color bar
    Color originalColor = g.getColor();
    for (int i = topY; i < bottomY; i++)
    {
      float farAlong = 1 - ((float) i) / bottomY;
      Color valueColor = converter.getColor((int) (farAlong * converter.getMaxValue()));
      g.setColor(valueColor);
      g.drawLine(barX, i, barX + barWidth, i);
    }
    g.setColor(originalColor);

    // Draw the vertical line of the bar
    g.drawLine(barX, topY, barX, bottomY);

    // Draw tick marks and labels
    int textHeight = g.getFontMetrics().getHeight();
    int textAdjust = (int) (textHeight / 2.6);
    for(int i = 0 ; i <= tickCount ; i++)
    {
      float ratio = (i/(float)tickCount);
      int y = bottomY - (int)(ratio * (bottomY - topY));
      Integer label = (int)(ratio * converter.getMaxValue());
      g.drawLine(barX, y, tickX, y);
      g.drawString(label.toString(), tickX + tickLabelGap, y + textAdjust);
    }
    g.dispose();
  }