How do I paint a Component, like a JPanel, into a Graphics of my choice, as if it were teh screen?
Had no luck on google.
What I have tried:
JPanel p = new JPanel();
p.setSize(32, 32);
p.setLocation(8, 8);
p.add(new JLabel(...));
p.add(new JLabel(...));
p.add(new ImageIcon(...));
Graphics g = getSomeGraphics();
p.paint(g);
however, this last instruction causes
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.RepaintManager.getVolatileOffscreenBuffer(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
...