I have a JPanel with vertical BoxLayout. It contains four components. I set the JPanel to LEFT_ALIGNMENT, which has no effect on its components. I set the first component to LEFT_ALIGNMENT, which has no effect. Only after I have set all four components to LEFT_ALIGNMENT do any of them align properly.
This suggests that it is impossible to have varying alignments in a container. They must all be the same alignment.
I accept that this is just the way things are: "Java works in mysterious ways." And I'm sure that it is possible to work around this limitation by stacking boxes that themselves have different internal alignments.
But I still wonder what in the world was going on in the minds of the
Java developers. Is there a rational reason for this oddity?
This raises my most serious criticism of Swing: the hidden gotcha. Swing is a tangled mess of cross-connecting requirements that are impossible to divine by simple inspection of the documentation. If you want to use, say, a JRadioButton, it's not enough to study the documentation on JRadioButtons; you must also consult lots of documents for which there is no obvious connection to JRadioButton other than it being part of Swing.
Of course, once you know everything there is to know about Swing, then it all makes perfect sense. And how does one learn everything there is to know about Swing? By working with it. But working with Swing doesn't reveal the hidden gotchas. Thus, the only way to learn about Swing is to spend a great deal of time studying the entire system in a purely theoretical approach, not daring to actually write code until you have the whole thing under your belt.
This is not good educational practice.
OK, I've gotten that off my chest.