Java Swing中是否有“Group Box”等价物?(Is there a “Group Box” equivalent in Java Swing?)

编程入门 行业动态 更新时间:2024-10-09 07:20:08
Java Swing中是否有“Group Box”等价物?(Is there a “Group Box” equivalent in Java Swing?)

尝试在Java / Swing中构建GUI应用程序。 我主要习惯于使用VB(或更准确地说,Gupta SQLWindows ...等)知道这是多少人,而在Windows上“绘画”GUI .-))。

我在Swing中找不到一个组Box的等价物

使用一个组框,您可以在几个相关的小部件周围有一个方框(通常带有标题)。 一个例子是围绕几个单选按钮的组合框(标题说明单选按钮是什么,例如“Box”标题为“Male”和“Female”单选按钮的组Box)。

我搜索了一下...我发现唯一的方法是添加子窗格,在子窗格中设置边框,然后将“组”中的所有窗口小部件添加到子窗格。 有没有更优雅的方式来做到这一点?

Trying to build a GUI application in Java/Swing. I'm mainly used to "painting" GUIs on the Windows side with tools like VB (or to be more precise, Gupta SQLWindows... wonder how many people know what that is ;-)).

I can't find an equivalent of a Group Box in Swing...

With a group box, you have a square box (usually with a title) around a couple of related widgets. One example is a group box around a few radio buttons (with the title explaining what the radio buttons are about, e.g. Group Box entitled "Sex" with "Male" and "Female" radio buttons).

I've searched around a bit... the only way I found was to add a sub-pane, set the border on the sub-pane and then add all the widgets in the "group" to the sub-pane. Is there a more elegant way to do that?

最满意答案

创建一个JPanel,并添加你的单选按钮。 不要忘记将JPanel的布局设置为适当的。

然后调用panel.setBorder(BorderFactory.createTitledBorder(name));

Create a JPanel, and add your radiobuttons to it. Don't forget to set the layout of the JPanel to something appropriate.

Then call panel.setBorder(BorderFactory.createTitledBorder(name));

更多推荐

本文发布于:2023-07-30 15:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:等价物   Swing   Java   Group   equivalent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!