// use setForeground and setBackground for the colors sclass JColorBar > JComponentWithChangeListeners { settableWithVar double value; settableWithVar double max = 100; *() { setForeground(Color.red); } public void paintComponent(Graphics g) { super.paintComponent(g); // paint background int w = getWidth(), h = getHeight(); fillRect(g, 0, 0, w*doubleRatio(value, max), h, getForeground()); } selfType max aka setMax(double max) { this.max = max; repaint(); this; } selfType value aka setValue(double value) { this.value = value; repaint(); this; } }