Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!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:16:13 -0800 Organization: A noiseless patient Spider Lines: 57 Message-ID: References: <4ebf9c51$0$5055$ba620e4c@news.skynet.be> <4ebfc473$0$5044$ba620e4c@news.skynet.be> <4ebffe4c$0$5045$ba620e4c@news.skynet.be> <4ec025cd$0$5046$ba620e4c@news.skynet.be> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 14 Nov 2011 00:16:15 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="14151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PYHih1RjYgCCodX6Qa8bU" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: <4ec025cd$0$5046$ba620e4c@news.skynet.be> Cancel-Lock: sha1:YDaoh6s0FcPJd6k/+7Xam/AaoR0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9943 On 11/13/2011 12:17 PM, Olivier Scalbert wrote: > On 11/13/2011 08:01 PM, Knute Johnson wrote: >> >> import java.awt.*; >> import java.awt.event.*; >> import javax.swing.*; >> >> public class test extends JPanel { >> public test() { >> super(new GridBagLayout()); >> >> GridBagConstraints c = new GridBagConstraints(); >> c.fill = GridBagConstraints.HORIZONTAL; >> c.gridy = 0; >> >> String labels[] = {"Button 1","Button 2", >> "Long Button 3","Button 4","Button 5"}; >> >> for (int i=0; i> add(new JButton(labels[i]),c); >> ++c.gridy; >> } >> } >> >> public static void main(String[] args) { >> EventQueue.invokeLater(new Runnable() { >> public void run() { >> JFrame f = new JFrame(); >> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); >> f.add(new test(),BorderLayout.EAST); >> f.setSize(700,500); >> f.setVisible(true); >> } >> }); >> } >> } >> > Ok, all the buttons have the same size and are aligned ! When I resize > the main frame, the group of buttons is in the EAST part but in the > middle of the frame height. Is it possible the have this group on top > (of the EAST part) ? -- Knute Johnson