The kneecap (or patella) is a small piece of bone, which is not fixed in place. It connects the shin bone to the thigh muscles with the patellar tendon and the quadriceps tendon. The kneecap sits inside the trochlea, which is a large groove in the upper part of the knee joint. The tension of the thigh muscles keeps the kneecap in the trochlea. A high speed injury is usually needed to move the kneecap out of the trochlea, so it hardly ever pops out unless you have an accident in a car, motorcycle, or during sporting.
The dislocation of the patella can be a serious injury, as other tendons usually get hurt too. So even if it pops back in place, or you push it back yourself you should visit the doctor anyway.
For some people the patella is loose and can jump out ot place almost by itself - usually it's not such a big issue. Physical therapy and proper exercises can help to keep the patella in place, and wearing a brace can help too.
In short, just do not do it! Leave this to a doctor if possible. If you had a serious accident your knee (and you) could have had other injuries too and you'll need to visit the doctor anyway. If you want to do it yourself anyway, here's how you can go forward:
Very loose tendons, shallow trochlea or other personal differences can lead to the knee dislocating and then popping back in. Make sure you got not other injury, and go to a doctor ASAP if you are not sure you are 100% OK. A knee dislocating spontaneously could lead to falls and other injuries which could make the issue even worse in the long term. That's why it's important to handle it with a combination of physical therapy, exercises and wearing a brace.
The shallow trochlea is a typical bone malformation that can cause the patella to slip out of it's location.
You should imagine this exactly as it's said: the groove the patella sits in is not deep enough, so even a small hit can cause it to jump out.
You can compensate for a shallow troclea with exercises and wearing a brace, serious cases may need a surgery too.
Straight leg raises are great to start strengthening your thigh muscles.
Just lie on your back with your legs held straight. For support, bend your knee on your healthy side and place your foot on the floor. On your injured side slowly raise your leg until your ankle is about 8 inches from the floor. Keep your leg straight while raising it. Hold it a bit then let it down slowly. Do three sets of this exercise with 15 repetitions.
You can also raise your leg 45 degrees towards the outer side (left leg towards the left side or right leg towards the right side), with your toes pointing outwards at 45 degrees.
Do this for three weeks to build a bit of strength, and advance to the next exercises only afterwards.
Just keep it simple when doing step-ups. Get a small support, about 4 inches high (a single step of a staircase is just right). Step on it with your injured leg, while keeping your shin straight. Slowly shift your weight to your injured leg, and straighten it. Your healthy leg will rise from the floor.
Once your injured leg is straight slowly bend it again and let your healthy leg slowly back to the ground. Do 3 times 15 repetitions of this exercise.
It's important to keep your lower leg planted straightly on the ground while straightening it. Use a rail to hold onto if you do not feel secure.
Wall squats are advanced exercises, only try them if the previous ones are already going really well.
Stand with your back against a wall, and place a soccer ball or basketball between the middle of your back and the wall. Next slowly squat down until your thighs are horizontal. Hold it a bit, then push yourself back up. Take care that your feet are always in front of your knees. (That is your shin bone is bending towards the wall or is straight.)
This exercise will need time, keep doing it day after day and work yourself up to 3 sets with 15 repetitions.
You can also use a slippery surface with a towel too instead of a ball. If the exercise is too easy for you, try putting a ball between your knees, and squeeze while you are squatting.
If your knee slips out of place, continue the exercises and get a brace.
Cons The knee brace is too warm, and patella is not protected from falling as it's open. The brace has metal in it so you'll have to take it off for airport security, MRI and X-ray. The material is not really waterproof. There is a chance that the velcro may give in. For best results do not wash it in a washing machine.
Pros The Winzone brace stabilizes the patella, the metal stabilizers prevent lateral movement. The brace helps with patella pain and stops the patella from moving around (it stops intermittent patella instability). As for sports it works well for biking, walking and running, and works for almost all thigh sizes durable. The product is latex free and stays in place well.
Cons The knee strap is not really suitable to wear above clothing. The product is OK for running but may not work for high intensity workouts such as crossfit. The knee strap is fairly simple, and may not help with all the pain a brace can help with.
Pros The strap is great for running. It survives the washing machine, but for best results hand wash it. It's suitable for swimming too and not noticeable under clothes. The strap effectively keeps the patella from moving around or sliding. The strap has a strong velcro, so it stays well in place. It's also latex free and soft enough so it will not bruise your knee. It's not as bulky as a full-size brace so it surely will not make you sweat and will not cut off your circulation.
Cons Fitting the velcro on this brace can be hard at first. Regular heavy use could wear it out in a year or so. The brace may have a neoprene smell that vanishes after some time - this is expected as the brace contains neoprene. This brace is probably not the best choice for patella support.
Pros On the upside, you can wear the brace all day long, or for the nights too. The brace supports the knees as expected and the sizing works really well. The brace has a strong velcro so it does not slip, and stabilizes the patella.
The product is good for most sports, and getting it wet won't harm it either. It contains no latex so you will not get latex allergy wearing it, and no metals, so you won't have airport security issues either.
Cons This patella knee strap does not work for everyone. It slides down sometimes and can get worn down fast.
Pros This knee strap is suitable for housework, and sports like walking, running and tennis too. It is not as bulky as a full sized brace so you'll be able to move a bit more freely. It very comfortable so wearing it for the night works too.
The strap keeps the patella in place and works for patellar tendinitis too. As it stabilizes the patella it will help you avoid dislocation.
You can wear it under or over your clothing too. The strap has no metal inside, and has a gel pad that's why it's so comfortable. Overall it's very well made.
Cons This knee brace is made of neoprene, so it will have some neoprene smell initially. The material is thick, so you will feel warm wearing it and it takes long time to dry after washing. As it's a bit more complex than your average brace, putting it on will take more time. The material does not hold up well for some.
Pros The brace contains no metal, and has strong velcro straps. Due to the extra layer the brace itself does not touch your skin so it will not cause skin irritation. It's suitable for patella stabilization and can help tendon strain all day long. EzyFit has great support so you can rely on this brand. You can wear it under your clothes if you'd like to.
The London Knee Clinic has a concise article on patella dislocation here.