Roman
Roman

Reputation: 131048

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?

Upvotes: 20

Views: 27207

Answers (2)

Ascalonian
Ascalonian

Reputation: 15174

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);

Upvotes: 29

Devon_C_Miller
Devon_C_Miller

Reputation: 16518

Create a JSeparator and add it between button and label.

Upvotes: 3

Related Questions