Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: How to align swing buttons vertically ? Date: Sun, 13 Nov 2011 16:28:05 -0800 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <4ebf9c51$0$5055$ba620e4c@news.skynet.be> <4ebfc473$0$5044$ba620e4c@news.skynet.be> <4ebffe4c$0$5045$ba620e4c@news.skynet.be> <2442894.209.1321211019540.JavaMail.geo-discussion-forums@prew38> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 14 Nov 2011 00:28:06 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="17256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OrxWk224Og7w//kqFx1iu" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <2442894.209.1321211019540.JavaMail.geo-discussion-forums@prew38> Cancel-Lock: sha1:buREYL9u0/0TxHz7lcqswVjVRJ8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9944 On 11/13/2011 11:03 AM, Lew wrote: > Olivier Scalbert wrote: >> Perhaps I have not understand, but with the following code, buttons are >> not well aligned: >> >> import java.awt.*; >> import javax.swing.*; >> >> public class TestViewer { >> >> public static void main(String[] args) { >> EventQueue.invokeLater(new Runnable() { >> public void run() { >> JFrame frame = new ViewerFrame(); >> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >> frame.setSize(800, 600); > > Shouldn't you call 'pack()' right here? Layouts often don't work well without it. The OP created a pretty good SSCCE here and for that purpose pack() would not demonstrate what he wanted to show. The only possible problem he would have with the LayoutManager is too little space to display his example. Most of the time, having extra space in a frame isn't going to cause any display problems. I think he can be forgiven for not packing this time (as I hope I can for my example :-). -- Knute Johnson