views:

66

answers:

2

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?

+2  A: 

Create a JSeparator and add it between button and label.

Devon_C_Miller
+4  A: 

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);
Ascalonian
+1, for mentioning the tutorial, (now if only we could get the guy to read it and quit wasting our time). -1, for the edit (this guy does not need any spoon feeding of code otherwise he will never learn how to problem solve on his own).
camickr
I provided an unbiased answer, just like I would with anyone else who is trying to learn on here. Yes, you should try to RTFM. But if you don't know what exactly to look for, or don't have the time to keep reading, it is better to come to SO and learn. Just my opinion.
Ascalonian
@Ascalonian, thanks for the answer. It exactly what I needed.
Roman
@Roman: You are welcome!
Ascalonian
@Ascalonian, I totally share you opinion. For some kinds of questions I read tutorials. For other kinds of questions, I think, it is more reasonable to ask them here. And as a prove of my point I get good answers (like yours) and my questions are up voted by other users. But this guy (camickr) is following me and after every my question he says me that I should not ask here anything and other users should not answer my questions. It kind of strange and funny. :)
Roman
Have you even read any of his previous questions? There are multiple repeating questions all about the same basic topic because he hasn't taken any time to learn the basics first. If you don't have a foundation in the basics then you don't have the ability to think about how you might possibly solve the problem. It only takes a minute to browse the table of contents in the tutorial to see what components are available. There is no excuse for not doing that first before posting a question, given that most of his previous question point him to the tutorial anyway.
camickr
"Give somebody a fish they eat for a day. Teach somebody to fish they eat for life". And I never said you shouldn't "ask questions here". All I have been saying is you should do a little work on your own. We have already done the hard part of pointing you to the tutorial. The least you can do is browse the table of contents. If you had, you would have noticed the JSeparator component and hopefully wondered what it is used for. That is how you "slowly" gain knowledge over time.
camickr
@camickr: I can understand where you are coming from. However, there are times where you are working on multiple things and can't afford the time. For example, I was thrown onto a project at work that I had limited knowledge of. I was also balancing 3 other projects with the same deadline. Instead of wasting hours researching and testing, I went to SO for some help and was able to get the project done on time. I would have spent too much time reading the tutorials.
Ascalonian
I also don't mean to sound rude or anything, since you are obviously an awesome contributor to SO (nice rep points!)... but I don't think this question should be a bitch session about someone's work ethic of trying to get answers. I would like to see this focused on the question. Although... I would LOVE to see your point of view in the Community Wiki and see what other people say about it :-)
Ascalonian