During practice, swimmers wear caps to keep there hair out of the way, but in performances they use Knox gelatin to keep it in place. During performances, swimmers where there hair in a tight bun and a couple layers of Knox is brushed over there hair to keep in place. 

Here is a good guide to knoxing!