Re: How to implement tab order?
I don't think that this is very good advice, nothing personal mind
you, but I have been coding Swing for years and I prefer it when
people use a different GBC for each component placed for
I have to strongly disagree with you. It does depends upon the layout
and how the code is structured, but looking at most straightforward code
keeping constraint builders avoids copy & paste repetition and is easier
A typical layout will have components with similar constraints.
Repetition of code to set these up is not good. There are a number of
approaches. You can simply use the same constraint builder multiple
times (note: you may have multiple builders in place at once, for
instance one for labels and one for text fields). Or you might well
factor out adding a type of component into a method (and use the
constraint builder only once).
The cost of constructing a GBC is tiny in terms of performance and
Absolutely. Probably the most significant performance/memory cost is in
the extra code, which at a byte code level should be quite small. A
single extra inner class will probably be more expensive, and I wouldn't
argue against those.
This sort of optimization seems unnecessary, and probably contributes
to the myth that GridBagLayout is hard to use.
It isn't intended to be an optimisation. Or at least only an
optimisation in that it makes the programmer's life easier.
Unemployed English Java programmer