Q:

Painting a circle at the center of JButton

I want to paint a circle at the middle of JButton. Here is what I tried:
JButton jButton = new JButton(new CircleIcon());

public class CircleIcon implements Icon{
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.drawOval(10, 10, 20, 20);
    } 

    @Override
    public int getIconWidth() {
        return 10;
    }

    @Override
    public int getIconHeight() {
        return 10;
    }
}

I got this:

But I need something like this:

My question is what is the quare in the middle of the button on the first picture? And how to make it as in the second one?

A:

what is the quare in the middle of the button on the first picture?

You have probably painted a rectangle over your codes.  You should just look for drawRectangle( code line on your code block.

how to make it as in the second one?

There are 2 possible solution for it. 
1 - You can set some size for the button. Because it seems need to get bigger to be seen like the latter picture. Try this 
jButton.setPreferredSize(new Dimension(40, 40));

2 - You are using static values to draw a circle. I would use dynamic values for it. just like this. 
             JButton JButton = new JButton() {
                @Override
                protected void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    int nGap = 10;
                    int nXPosition = nGap;
                    int nYPosition = nGap;
                    int nWidth = getWidth() - nGap * 2;
                    int nHeight = getHeight() - nGap * 2;

                    g.setColor(Color.RED);
                    g.drawOval(nXPosition, nYPosition, nWidth, nHeight);
                    g.fillOval(nXPosition, nYPosition, nWidth, nHeight);

                }
            };

            JButton.setHorizontalAlignment(JLabel.CENTER);
            JButton.setVerticalAlignment(JLabel.CENTER);

This is the button display at different sizes. 

A:

The Swing tutorial on How to Use Icons should help: Creating a Custom Icon Implementation
import java.awt.*;
import javax.swing.*;
public class CircleIconTest {
  public JComponent makeUI() {
    JPanel p = new JPanel();
    p.add(new JButton(new CircleIcon()));
    return p;
  }
  public static void main(String... args) {
    EventQueue.invokeLater(() -> {
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      f.getContentPane().add(new CircleIconTest().makeUI());
      f.setSize(320, 240);
      f.setLocationRelativeTo(null);
      f.setVisible(true);
    });
  }
}
class CircleIcon implements Icon {
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    //g.drawOval(10, 10, 20, 20);
    Graphics2D g2 = (Graphics2D) g.create();
    //Draw the icon at the specified x, y location:
    g2.drawOval(x, y, getIconWidth() - 1, getIconHeight() - 1);
    //or
    //g2.translate(x, y);
    //g2.drawOval(0, 0, getIconWidth() - 1, getIconHeight() - 1);
    g2.dispose();
  }

  @Override
  public int getIconWidth() {
    return 20;
  }

  @Override
  public int getIconHeight() {
    return 20;
  }
}

A:

jButton.setFocusPainted(false); // This will prevent the square highlight on focus!

