This little utility method is handy for making components the same width where the new width is the maximum width of the component arguments. Using varargs you can pass in either a comma separated list of components or an array of components.
Paul Clapham wrote:You could consider a factory pattern:
This has an advantage over an array or list of buttons, namely that you can use variables with meaningful names.
Thanks. I haven't thought of it. Would it be even more efficient to pass the new button as an argument (as below), the method serving the purpose of only configuring it? I guess it can't be called a factory method in such case, however...
Thanks for the suggestion Carey. I might not use this exact method, but I'll consider using this approach elsewhere in my small app.
Another reason to use the Factory approach would be if at some point you wanted to alter the standard button's behaviour, which involved sub-classing JButton. The factory method could hide all that from the application and continue to return an instance of a JButton. No changes would be required for the application code to utilize the new behaviour.
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop