Java 中是否有字段集(HTML)的等价物?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10820724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:43:56  来源:igfitidea点击:

Is there an equivalent in Java for fieldset (HTML)?

javaswingswtawt

提问by RedhopIT

Is there an element in Java (i.e. Swing/AWT or SWT) that is equivalent to the HTML element fieldset?

Java 中是否有与 HTML 元素等效的元素(即 Swing/AWT 或 SWT)fieldset

回答by Pier-Alexandre Bouchard

Create a Panel, create a titled border and you will be able to put inside all your field components.

创建一个面板,创建一个有标题的边框,您将能够将所有字段组件放入其中。

JPanel panel = new JPanel();
panel.add(new JLabel("foo"));
panel.setBorder(BorderFactory.createTitledBorder("bar")); 

回答by Jeshurun

Have a look at javax.swing.border.TitledBorder. You can set them on panels and are similar in appearance to HTML fieldsets.

看看javax.swing.border.TitledBorder。您可以在面板上设置它们并且在外观上类似于 HTML 字段集。

Border titleBorder = new TitledBorder(new LineBorder(Color.RED), "Fieldset");

You could then add the border to your panel using the setBorder()method.

然后,您可以使用该setBorder()方法将边框添加到面板中。

回答by Adam Arold

If you are using SWT than I think that org.eclipse.swt.widgets.Groupis what you are looking for. It is a Composite(a block in HTML analogy) and it looks like a fieldset in HTML.

如果您使用的是 SWT,那么我认为这org.eclipse.swt.widgets.Group就是您要寻找的。它是一个Composite(类比 HTML 中的块),它看起来像 HTML 中的字段集。

I can't speak for AWT and SWING however.

但是,我不能代表 AWT 和 SWING。