Search code examples
javajpanelborderdotted-line

Java add a Dashed or dotted border to a JPanel


I am having problems with this thing: can I, in some way, add a dashed (or dotted, no matter) border to a JPanel?

I searched SO questions but seems that no one asked this before.

I'm wondering if is there any class to use. actually I am using:

myPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

Obviously this is a standard class that give only few standard borders, no one is useful for me.


Solution

  • You're looking for BorderFactory.createDashedBorder(Paint).