Rounded borders on a JPanel

15,253

Maybe here is a way to paint RoundedLineBorder; please be careful with constants for nice output to the GUI.

Share:
15,253
Doug
Author by

Doug

Updated on June 04, 2022

Comments

  • Doug
    Doug almost 2 years

    What I've got here is a JPanel with a rounded border that is set up as such:

    panel.setBorder(new LineBorder(PanelColor, 5, true));
    

    The problem is, in each of the corners there are 2 diagonal opaque lines going from the outer corner to the inner corner that is the length of the border. Whatever is behind the border shows through. Is there any way to get rid of these lines and make the entire border one solid color? Thanks!

    I'd attach a picture but I don't have enough rep to do so :P

    • Andrew Thompson
      Andrew Thompson over 12 years
      "I'd attach a picture but I don't have enough rep to do so" You can always upload the image to an image hosting site and include a link. If it is a good description of the problem, and not too large in pixels or bytes, someone else might embed it into the question for you. See also How do I create a screenshot to illustrate a post? (hopefully to soon become part of the SE FAQ) for tips on making screenshots.
  • Doug
    Doug almost 13 years
    Yes this is true, whatever is behind the rounded panel shows through. I have other colored panels that can be moved around and when they are place beneath the panel with the rounded edges their colors show up instead of the white lines. I should have made it clear that they're not always white.
  • Doug
    Doug almost 13 years
    Huh, this fixed the problem I just had to change drawRoundRect to fillRoundRect in order to have the whole border a solid color. Why on earth the default rounded border would not work like this I do not know. Thanks for the help!
  • mKorbel
    mKorbel almost 13 years
    @Doug you are welcome, that's about compound Border (Empty + Line), which covered corners up-to 2-3pixels