James was involved in the 1488 rebellion that saw his father, James III, killed at the Battle of Sauchieburn. As a 15 year old boy, it is unclear what he expected as the outcome of the rebellion but it seems clear that he carried the guilt of his father's death into his adult life. After the battle James did penance for his role in the rebellion and was to wear a celice – an uncomfortable metal chain – around his waist for the rest of his life.
Like his forefathers, James' reign was marked by the factional interests of the nobles in his court and, like previous Stewart monarchs, James fought to counter these to centralise power in his own hands.
James IV has been acclaimed by historians as the first true Renaissance king of Scotland. Under his rule, James patronised the arts and sciences and Scotland flourished as a result. It was during his reign that the first printing press was established in Scotland (1305).
During the same period James brought order to the Scottish kingdom. In 1493 he finished the work of previous Stewart kings in effectively ending the influence of the Lords of the Isles. From that date onward, the King of Scots would hold that title.
In 1502 he signed the Treaty of Perpetual Peace with Henry VII of England that went some way to ease the traditional enmity between the two nations. To cap the new warm relations with the old enemy James married Henry's daughter, Margaret Tudor in 1503.
This was an important marriage for both nations. For Henry, the marriage into one of Europe's most established monarchies gave a patina of legitimacy to the new Tudor royal line. For James, the marriage raised the interesting opportunity of a future offspring of the marriage having a claim to the English throne.
The new peace and goodwill established between the two nations lasted until 1513 when international matters forced James to make the most difficult of decisions. As part of a long-running conflict in Italy, England and France ended up at war. Under the obligations of the Auld Alliance (signed by John Balliol in 1295) James was honour-bound to aid the French and invade England. This was naturally at odds with the Treaty he had signed with Henry VII in 1502.
James made up his mind. He declared war on England and led his army south. The campaign was a disaster. On the 9th September 1513 James led his army into battle at Flodden, Northumberland. The Scots were slaughtered with many of the Scottish nobility killed. James was one of that number.
As a final side note, James was the last King of Scots to speak Gaelic.