Pregunta

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

Thank you

¿Fue útil?

Solución

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.

Otros consejos

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.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top