Marko Zajc
Marko Zajc

Reputation: 323

JPanel background color spills out of borders on some border types

When setting a border to a JPanel (in my case Titled border + Line border, but also appears on some other borders, the background color of JPanel will spill out making it look ugly as hell. Here's a demonstration:

Ugliest thing I've enet seen

The only way i can make it look normal is to create another JPanel behind this one, make it white and make this one transparent:

That's way better

So is there a way i can fix this or is it just how Swing works?

By the way, for changing background of a JPanel, i call

panel.setBackground(Color.WHITE);,

To set the border i call

panel.setBorder(new TitledBorder(new LineBorder(new Color(169, 169, 169)), "Settings", TitledBorder.LEADING, TitledBorder.TOP, null, null));

and as LaF, i use Windows10's LaF.

Upvotes: 1

Views: 883

Answers (1)

c0der
c0der

Reputation: 18792

The Title is part of the JPanel so the area behind it is painted with the background color.
Using TitledBorder.BELOW_TOP makes it look like:

enter image description here

Upvotes: 2

Related Questions