If you are just using electric, you'll need to train them to it first.
However we have a small "training pen" about 20ft * 10 ft which we put weaners into. This has stock wire round it loosely attached to fence posts with the electric tape on the inside. When weaners touch the tape, they can not go forward as they see the stick wire, so go backward. After 2-3 days we can then move them to an area with just tape.
If you just put them into an electric fenced area without training, it is 50/50 as to whether they will go forward or back when first shocked, and you can quite easily teach your pigs to escape when shocked, rather than be enclosed.
Then you can keep them just behind electric, which means that you can be flexible in what area you give them.
We keep sows just behind a single strand of electric tape, growers behind two strands. This gives a flexible solution that lets you expand the area or move it easily and cheaply.
4 caveats though.
1. Pigs must be trained to it, easily done by having a training area - stock wire with electric round the inside. A week or so in there and the pigs learn about the electric.
2. If they do get out, they must be to somewhere safe - eg still within your ground, they will not run immediately to the next fence and break out, but will spend hours exploring what is in between. So if your ground has some sort of fencing that would stop a pig wandering out of your land, the once trained you can use electric to create an area within it for your pigs.
3. If you are heavy deer country then deer can take the electric away (hence rule 2), and don't do this in the middle of a badger set - you should site pigs away from badgers in any case as there is a TB risk.
4. Pigs can get out from this system, but very rarely do. However If they do, you must be prepared for their inquisitive consequences, so don't site your pigs next to your prize vegetable patch, or beautifully manicured lawn.
We like using electric tape (horse tape) as the pigs see it clearly and so avoid it.
If you can't do the above, then stock wire with electric on the inside provides a secure solution. I don't like using barbed wire - risk of damage to pig. Plain stock fencing may work, but as the inside gets "used", and pigs get bigger it is likely that the pigs will simply lift the fence up and get out.
Pigs don't escape (as in feeling like they are in a prison), they merely wish to explore new opportunities for better rooting, so move an obstacle that is in their way.