Java Swing Gridlayout VERTICAL 约束

发布于 2024-12-27 02:42:24 字数 58 浏览 3 评论 0原文

是否可以在 Gridlayout 中垂直添加组件?我的意思是下一个在上一个之上?

谢谢

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

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太阳男子 2025-01-03 02:42:24

不,没有任何布局允许您从下到上垂直堆叠,至少我知道。如果您想要垂直堆叠,可以使用带有单列的 GridLayout 或带有垂直轴的 BoxLayout。通过嵌套面板和组合布局,您应该可以轻松获得所需的内容,例如,具有垂直布局的面板全部放置在水平容器中。

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.

-小熊_ 2025-01-03 02:42:24

像 BoxLayout 和 GridLayout 这样的布局在使用:时会从上到下显示组件,

panel.add( someComponent );

但您始终可以使用:

panel.add(someComponent, 0);

在顶部插入组件。

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.

撩起发的微风 2025-01-03 02:42:24

虽然这个答案与网格布局无关,但我强烈建议使用 JGoodies 表单布局。其高度灵活。 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));

您可以手动编写代码以在设计的定义布局中的任何位置绘制每个组件,即针对列和行。 均匀垂直排列。
阅读白皮书:http://www.jgoodies.com/articles/forms.pdf

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文