Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: How to align swing buttons vertically ? Date: Sun, 13 Nov 2011 19:17:31 +0000 (UTC) Organization: UK Free Software Network Lines: 50 Message-ID: References: <4ebf9c51$0$5055$ba620e4c@news.skynet.be> <4ebfc473$0$5044$ba620e4c@news.skynet.be> <4ebffe4c$0$5045$ba620e4c@news.skynet.be> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1321211851 3454 84.45.235.129 (13 Nov 2011 19:17:31 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sun, 13 Nov 2011 19:17:31 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9929 On Sun, 13 Nov 2011 18:28:44 +0100, Olivier Scalbert wrote: > On 11/13/2011 03:38 PM, Martin Gregorie wrote: >> That's nothing to do with the layout. It aligns the objects you're >> laying out by doing its best with the sizes of the objects you created. >> >> JButton inherits size setting methods (setMaximumSize, setMinimumSize, >> setPreferredSize) from JComponent. Use them to control button size. >> > Perhaps I have not understand, but with the following code, buttons are > not well aligned: > They aligned as I'd expect: - btnPanel is sized to contain the buttons and nothing else and is placed as you asked, on the east side of the content pane. - The buttons have their centres aligned. I don't understand what you mean by "not well aligned": - If you want the buttons to appear as other than a close-packed block, take a look at "How to use BoxLayout" in the Java tutorial. It is also referenced from the the class description in the BoxLayout javadocs entry. - If you want all buttons to be the same size, use a custom class in place of JButton: import java.awt.*; import javax.swing.*; class MyButton extends JButton { public MyButton(String label) { super(label); Dimension d = new Dimension(120, 30); setMinimumSize(d); setMaximumSize(d); setPreferredSize(d); } } -- martin@ | Martin Gregorie gregorie. | Essex, UK org |