This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
According to this article: "One big difference between BoxLayout and many earlier layout managers is that BoxLayout respects each component's maximum size and X/Y alignment."
My guess is that JRadioButtons have a default alignment of left, at the component level. A BoxLayout won't override that. If you want your radio buttons to be centered (although I have no idea why you'd want that), you'd have to use the setAlignmentY() method of your button instances.
The CENTER option used when adding to a BorderLayout simply dictates what "region" of the layout to put the component in--not how to align that component when it's in that region. Regions expand to fill up empty space, so if you don't have anything in your WEST or EAST regions, it will probably behave pretty much like a BoxLayout.
Okay, so why did they come out centered in the first version of your code? Not sure. Maybe because you never set up a layout manager for the panelTop JPanel? That will give it the default FlowLayout, which, from what I gather, does not respect the components' own alignments.
That's a little unexpected, if you ask me. I wouldn't thought that the alignment in the layou the buttons were in would've taken precedence over the alignment in the layout of the "parent" container.
I'm curious to see what sort of other answers this question gets.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus