是否有一个“分组框"?等价于Java Swing? [英] Is there a "Group Box" equivalent in Java Swing?

查看:85
本文介绍了是否有一个“分组框"?等价于Java Swing?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Java/Swing中构建GUI应用程序.我主要习惯于使用VB之类的工具在Windows方面绘制" GUI(或更准确地说,是Gupta SQLWindows ...想知道有多少人知道这是什么;-)).

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 ;-)).

我在Swing中找不到等效的Group Box ...

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的布局设置为适当的位置.

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

然后致电panel.setBorder(BorderFactory.createTitledBorder(name));

这篇关于是否有一个“分组框"?等价于Java Swing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆