尝试在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));
更多推荐
发布评论