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 made an attempt with the following code segment:
//Coloca color de arista y dibuja figura g.setColor(Color.BLACK); g.drawPolygon(figura); //Coloca color de fondo y rellena la figura g.setColor(Color.WHITE); g.fillPolygon(figura);
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 like 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);
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 some lines that would unite 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 solution to this problem, thank you.