View Single Post
  #1 (permalink)  
Old 07-31-2007, 05:29 AM
carl carl is offline
Member
 
Join Date: Jul 2007
Posts: 35
carl is on a distinguished road
Draw on JPanel, Help
Hi, I'm trying to draw using Graphics2D on a Java JPanel. Actually its a ImagePanel - a class I've extended from a JPanel, which just loads a jpeg into the panel. This part works fine....but then I want to draw on top of the JPanel, and its not showing what I'm drawing. Here is the code for the paint in the jpanel

Code:
protected void paintComponent(Graphics g) { System.out.println("in paintstuff"); super.paintComponent(g); if(text) { System.out.println("Here"); Graphics2D g2 = (Graphics2D)image.getGraphics(); g2.drawString(textString, lastX, lastY); text = false; } if (image == null) return; switch (style) { case TILED: drawTiled(g); break; case SCALED: Dimension d = getSize(); g.drawImage(image, 0, 0, d.width, d.height, null); break; case ACTUAL: drawActual(g); break; } }
Its definitely getting into the if(text) clause, and I've tried writing directly to the g Graphics, but that doesn't work either. "image" is just a BufferedImage storing the JPEG and whatever else I want to have drawn.

Thanks.
Reply With Quote
Sponsored Links