// use setForeground and setBackground for the colors // TODO: repaint more sparingly sclass JColorBar > JComponentWithChangeListeners { settableWithVar double value; settableWithVar double max = 100; *() { setForeground(Color.red); for (var : ll(varValue(), varMax())) var.onChange(l0 repaint); jMinSize(50, 10, this); } public void paintComponent(Graphics g) { super.paintComponent(g); // paint background int w = getWidth(), h = getHeight(); fillRect(g, 0, 0, iround(w*clampZeroToOne(doubleRatio(value, max))), h, getForeground()); } }