0

I have an array with multiple Grapics2D Objects and want to draw all of them in a Panel. Its not drawing anything. Does anyone know how to fix this?

for (Graphics2D g2d : models) {
     myPanel.paint(g2d);
}
camickr
  • 321,443
  • 19
  • 166
  • 288
  • 2
    The above code is completely wrong. Read the Swing tutorial on [Custom Painting](https://docs.oracle.com/javase/tutorial/uiswing/painting/index.html) for more information on painting basics and working examples. You can also check out: [Custom Painting Approaches](https://tips4java.wordpress.com/2009/05/08/custom-painting-approaches/) for an example that paints all the objects in an ArrayList. – camickr Sep 29 '21 at 14:01
  • This code is very strange. Normally the framework calls your component to paint it, passing in a Graphics2D, and for a JPanel, you override paintComponent, not paint. Where are you getting these Graphics2D objects? Why are you calling paint like this? – David Conrad Sep 29 '21 at 14:05
  • 2
    Also, it doesn't make any sense to talk about drawing a Graphics2D in a Panel. A Graphics2D isn't something you draw, it's something you draw *with*. – David Conrad Sep 29 '21 at 14:07
  • Complete examples are cited [here](https://stackoverflow.com/a/38293273/230513). – trashgod Sep 30 '21 at 14:36

0 Answers0