Robert could have, but decided not to, although Eddard basically did it for him by altering his will; Tywin was waiting for Jaime to be removed from the Kingsguard, but fully intended to disinherit Tyrion.
As for how Robb did it, he basically wrote it down in his will that Jon was his heir specifically, ahead of all other claimants.