java 如何在垂直排序的元素之间放置一条水平线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2567559/
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
How can I put a horizontal line between vertically ordered elements?
提问by Roman
I have a set of vertically ordered elements. They are displayed with the following code:
我有一组垂直排序的元素。它们与以下代码一起显示:
JPanel myPanel = new JPanel();
myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS));
JButton button = new JButton("My Button");
JLabel label = new JLabel("My label!!!!!!!!!!!");
myPanel.add(button);
myPanel.add(label);
I would like to put a horizontal line between my elements (something like <hr>in html). Does anybody know how it can be done?
我想在我的元素之间放置一条水平线(类似于<hr>html)。有谁知道怎么做?
回答by Ascalonian
回答by Devon_C_Miller
Create a JSeparator and add it between button and label.
创建一个 JSeparator 并将其添加到按钮和标签之间。

