@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
Slider slider = (Slider)getComponent();
int width = getWidth();
int height = getHeight();
graphics.setColor(trackColor);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (slider.getOrientation() == Orientation.HORIZONTAL) {
graphics.fillRect(0, (height - trackWidth) / 2, width, trackWidth);
if (tickSpacing > 0) {
int start = slider.getStart();
int end = slider.getEnd();
int value = start;
while (value <= end) {
float ratio = (float)(value - start) / (end - start);
int x = (int) (width * ratio);
graphics.drawLine(x, height / 3, x, height * 2 / 3);
value += tickSpacing;
}
}
} else {
graphics.fillRect((width - trackWidth) / 2, 0, trackWidth, height);
if (tickSpacing > 0) {
int start = slider.getStart();
int end = slider.getEnd();
int value = start;
while (value <= end) {
float ratio = (float)(value - start) / (end - start);
int y = (int) (height * ratio);
graphics.drawLine(width / 3, y, width * 2 / 3, y);