1

I have a program with a bunch of fields in a single panel, both labels and text fields. I needed to separate them somehow with a line to make it easier to read.

I have the panel built with SpringLayout. I was wondering if there is an easy way to create a horizontal line in SpringLayout without dividing the panel into 2, and adding a divider panel in between them.

Thanks!

1 Answer 1

3

I think the best practice would be creating another JPanel, but if I correctly understood your problem, maybe an alternative can be create a JSeparator:

JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
separator.setPreferredSize(new Dimension(200,3));
1
  • Thank you, I tried using JSeparator but nothing was showing up, but I wasn't putting a size on it so I guess the size defaulted to 0? But doing what you said did create a horizontal line the way i needed. Thanks a bunch! :)
    – Caveman42
    Nov 5, 2012 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.