Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). Does anybody know how it can be done?

like image 614
Roman Avatar asked Apr 02 '10 15:04

Roman


2 Answers

Use a 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);
like image 192
Ascalonian Avatar answered Nov 14 '22 00:11

Ascalonian


Create a JSeparator and add it between button and label.

like image 30
Devon_C_Miller Avatar answered Nov 13 '22 23:11

Devon_C_Miller