title: How to draw dotted line around circular JButton?
body: <p>I have a couple of JButtons here and I would like to surround have a dashed border as the perimeter of each button. However. I can't figure out how to do it. Similar questions on stack overflow has been resolved with BorderFactory.createDashedBorder() but that creates a square boarder in my case.</p>
  <p><a href="https://i.stack.imgur.com/D6Yj5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D6Yj5.png" alt="enter image description here" /></a></p>
  <p>Here is the code for how I am currently implementing the buttons. Also, I am very new to Swing so I appreciate it if the solution can be as simple as possible</p>
  <pre><code>public class ColorButton extends JButton {
      private Color color;
  
      public ColorButton(Color color) {
          super();
          this.color = color;
          setOpaque(false);
          setFocusable(false);
          setContentAreaFilled(false);
          setBorderPainted(false);
          setPreferredSize(new Dimension(45, 45));
      }
  
      public void paintComponent(Graphics g) {
          int diameter = Math.min(getWidth(), getHeight());
          g.setColor(color);
          g.fillOval(getWidth() / 2 - diameter / 2, getHeight() / 2 - diameter / 2, diameter, diameter);
      }
  }
  </code></pre>