Only by using UNIX-like OS's, e.g. Linux, FreeBSD, Solaris etc.
Windows OS's always write less used program components from the RAM to the swap file, even if the RAM isn't fully used yet.
UNIX-like OS's buffer everything in the available RAM and only then start using the swap file. If the RAM is totally utilized and you start a new program, the least used components stored in RAM are written to swap space as well.
Which one of those methods is the best depends on what you want to do with the system, but I personally prefer the 'UNIX'-way of memory management.