Fill a Polygon in Java

I'm doing a little program in which I have come across a detail when trying to draw a polygon in a JPanel in which I want the color of its edges to be fully configurable as well as its background. I have made an attempt with the following Code segment:

// Place edge color and draw figure
            g.setColor (Color.BLACK);
            g.drawPolygon (figure);
// Place background color and fill in the figure
            g.setColor (Color.WHITE);
            g.fillPolygon (figure);

Note.To avoid extending the code further, the variable figure is of the Polygon type.

The previous code I have also adapted it in a very similar way for figures without vertices as a circle.

                                                g.setColor (figu.getColorArista ());
            g.drawOval (figu.getCentro (). x-radio, figu.getCentro (). y-radio, radio * 2, radio * 2);
            g.setColor (figu.getColorFondo ());
            g.fillOval (figu.getCentro (). x-radio, figu.getCentro (). y-radio, radio * 2, radio * 2);

Without further extending the program …. My results have not been quite good, resulting in something like the following:
enter the description of the image here

As you can see, you can see the change of color only on certain edges of the figure, this depends on the shape of the figure. I thought about making the whole figure of the same color and then simply draw lines to join all the vertices with the color of the edges so that they overlap the edge of the figure. I would appreciate if you shared a more formal or other form than the one that could give me a solution to this problem, thank you.