3

Is it possible to add components in a Gridlayout verticaly ? I mean the next one above the previous one ?

Thank you

Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
Vincent Roye
  • 2,751
  • 7
  • 33
  • 53
  • 2
    You should accept more answers. You've asked 55 questions yet accepted answers on less than half of them. – Paul Jan 16 '12 at 04:39

3 Answers3

3

No, there is no layout that allows you to stack vertically from the bottom up, at least that I'm aware of. If you want vertical stacking you can either use a GridLayout with a single column or a BoxLayout with a vertical axis. By nesting panels and combining layouts you should easily get what you need, e.g. panels with a vertical layout all laid out in a horizontal container.

Paul
  • 19,704
  • 14
  • 78
  • 96
  • Good use case for a [`List`](http://docs.oracle.com/javase/7/docs/api/java/util/List.html) or [`Deque`](http://docs.oracle.com/javase/7/docs/api/java/util/Deque.html) implementation. – trashgod Jan 16 '12 at 05:07
3

Layouts like BoxLayout and GridLayout display components from top to bottom when you use:

panel.add( someComponent );

but you can always use:

panel.add(someComponent, 0);

to insert components at the top.

camickr
  • 321,443
  • 19
  • 166
  • 288
1

Though this answer is not related to Grid layout, i would highly recommend using JGoodies forms layout. Its highly flexible. http://www.jgoodies.com/freeware/forms/index.html

                          /* 1                    2      3       4    5                   6     7      8       9*/      
            String col1 = "left:max(20dlu;pref), 3dlu, 70dlu, 15dlu,left:max(10dlu;pref),10dlu, 70dlu, 70dlu, 70dlu";
                          /* 1   2     3   4  5   6    7   8    */
            String row1 = "  p, 5dlu, p, 3dlu, p, 5dlu, p, 9dlu, ";
            FormLayout layout = new FormLayout( col1, row1 + row2 + row3 + row4 + row5 + row6);

            JPanel panel = new JPanel(layout); 
             panel.setBorder(Borders.DIALOG_BORDER);

            // Fill the table with labels and components.
            CellConstraints cc = new CellConstraints();
            panel.add(createSeparator("Registration Information"), cc.xyw(1, 1, 7));
            panel.add(new JLabel("Patient ID"), cc.xy(1, 3));
            panel.add(pid, cc.xyw(3, 3, 1));
            panel.add(new JLabel("Date and Time"), cc.xy(5, 3));

You can hand code to plot each component any where in the defined layout designed ie wrt to col and rows. Even vertical arrangement. Read whitepaper: http://www.jgoodies.com/articles/forms.pdf

alkber
  • 1,426
  • 2
  • 20
  • 26