简体   繁体   English

如何在垂直排序的元素之间放置水平线?

[英]How can I put a horizontal line between vertically ordered elements?

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). 我想在我的元素之间放一条水平线(类似于html中的<hr> )。 Does anybody know how it can be done? 有人知道怎么做吗?

Use a JSeparator. 使用JSeparator。 Check out this tutorial on it. 查看本教程

But for a quick answer, just use the following code: 但是要快速回答,只需使用以下代码:

myPanel.add(button);
myPanel.add(new JSeparator());
myPanel.add(label);

创建一个JSeparator并在按钮和标签之间添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置垂直排列的元素之间的距离? - How can I set distance between elements ordered vertically? 如何将元素从一个有序整数ArrayList添加到另一个整数有序ArrayList? - How can I add elements from one ordered integer ArrayList to another integer ordered ArrayList? 我怎样才能水平放置struts 2元素? - How i can put struts 2 elements horizontally? Android如何在首选项之间放置单杠 - Android how to put a horizontal bar between preferences 如何在 Jasper Report 中向条形图添加水平线? - How can I add horizontal line to bar chart in Jasper Report? 如何在一行上准确输入五个字符串,然后将每个字符串之间留有空格的字符串放出来? 爪哇 - How can I input exactly a five character string on a single line and then out put the string with spaces between each character? Java 如何在JFrameMenu子菜单中并行放置两个元素? - How can I put two elements in parallel in a JFrameMenu submenu? 如何将2个Java swing元素彼此叠加? - How can I put 2 java swing elements on top of each other? 如何获取Json数组中的元素并将内容放入arraylist中? - How can I take the elements in a Json array and put the contents in an arraylist? 如何在水平表格中垂直打印 - How to print vertically in a horizontal table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM