Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9943

Re: How to align swing buttons vertically ?

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 <nospam@knutejohnson.com>
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 <j9pmkf$dq7$1@dont-email.me> (permalink)
References <4ebf9c51$0$5055$ba620e4c@news.skynet.be> <j9oef0$ti8$2@localhost.localdomain> <4ebfc473$0$5044$ba620e4c@news.skynet.be> <j9okpi$va3$1@localhost.localdomain> <4ebffe4c$0$5045$ba620e4c@news.skynet.be> <j9p461$eqc$1@dont-email.me> <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

Show key headers only | View raw


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<labels.length; i++) {

             if (i == labels.length - 1) {  // last label
                 // anchor last button to north and give it
                 // a weighty of 1.0.  this will tell that
                 // button to take all remaining vertical
                 // space and will push all the other
                 // buttons to top of the container
                 c.anchor = GridBagConstraints.NORTH;
                 c.weighty = 1.0
             }

>>              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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to align swing buttons vertically ? Olivier Scalbert <olivier.scalbert@algosyn.com> - 2011-11-13 11:30 +0100
  Re: How to align swing buttons vertically ? Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-13 12:50 +0000
    Re: How to align swing buttons vertically ? Olivier Scalbert <olivier.scalbert@algosyn.com> - 2011-11-13 14:21 +0100
      Re: How to align swing buttons vertically ? Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-13 14:38 +0000
        Re: How to align swing buttons vertically ? Olivier Scalbert <olivier.scalbert@algosyn.com> - 2011-11-13 18:28 +0100
          Re: How to align swing buttons vertically ? Knute Johnson <nospam@knutejohnson.com> - 2011-11-13 11:01 -0800
            Re: How to align swing buttons vertically ? Olivier Scalbert <olivier.scalbert@algosyn.com> - 2011-11-13 21:17 +0100
              Re: How to align swing buttons vertically ? Knute Johnson <nospam@knutejohnson.com> - 2011-11-13 16:16 -0800
          Re: How to align swing buttons vertically ? Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-13 19:17 +0000
            Re: How to align swing buttons vertically ? Olivier Scalbert <olivier.scalbert@algosyn.com> - 2011-11-13 21:01 +0100
              Re: How to align swing buttons vertically ? "John B. Matthews" <nospam@nospam.invalid> - 2011-11-13 17:33 -0500
          Re: How to align swing buttons vertically ? Lew <lewbloch@gmail.com> - 2011-11-13 11:03 -0800
            Re: How to align swing buttons vertically ? Knute Johnson <nospam@knutejohnson.com> - 2011-11-13 16:28 -0800
  Re: How to align swing buttons vertically ? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-13 09:27 -0800

csiph-web