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 ?

From Knute Johnson <nospam@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: How to align swing buttons vertically ?
Date 2011-11-13 16:16 -0800
Organization A noiseless patient Spider
Message-ID <j9pmkf$dq7$1@dont-email.me> (permalink)
References (2 earlier) <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>

Show all headers | 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