And to pose a follow up question, how did a foreign monarch manage to hold on so tightly to a state which seemed to have had such a strong national and ethnic identity? Was it simply seen as the only (and preferable) alternative to Ottoman rule? I know that there was unrest and nationalistic sentiment to some degree and that this was the main reason for the Austro-Hungarian compromise, but I'd really like the finer points of this issue illuminated for me.
I can't say much about the Hungarian reaction, but the specific route the Habsburgs took to acquiring Hungary was convoluted, and Fate played a large part. Maximilian I was of the opinion that Hungary's position on Austria's eastern flank was a major security risk, and he wasn't wrong, as he himself had needed to reconquer Austrian territory from Hungary in the 1490s. In 1506, he convinced the Queen of Hungary to betroth her as-yet unborn child to his infant granddaughter Mary, assuming (rightly and luckily) that it would be a boy. On top of this, he agreed to a match between Princess Anna of Hungary and one of his grandsons, Ferdinand or Charles. Mere arrangements such as these, however, were easily broken- formal ceremonies with vows and witnesses made it all much more official, and so Maximilian invited the Hungarian royal children (as the Queen's child had, indeed, turned out to be a boy, Lajos) to Innsbruck for an definite pledging.
Mary travelled from Malines, but Charles and Ferdinand proved problematic. Charles was by this point old enough to decide on his own marriage and needed to pick someone suitable given that hr would inherit Spain. Ferdinand, meanwhile, was firmly ensconced in Spain and his guardian (another Ferdinand) had no intention of letting him travel. This left Maximilian with a dilemma as he had a Hungarian princess and nobody to wed her to, and so himself stood in on their behalf (Anna was 12 at this point and probably a little confused). Following later negotiations with the Hungarians, Maximilian agreed that if neither of his grandsons actually stepped up then Maximilian would marry Anna, but Ferdinand of Aragon snuffed it in 1516 and the younger Ferdinand was finally shuttled up to Vienna in 1521 to finish everything off.
With the Hungarian marriages secure, Maximilian was satisfied his eastern flank was (more) secure. He could not have known that Lajos, now his grandson-in-law, would drown in a stream after the defeat of Mohács against the Turks, leaving no one to inherit save his sister... who was now married to Ferdinand von Habsburg, the new king of Hungary.
A. Wheatcroft, "The Habsburgs: Embodying Empire" (Penguin, 1996)