MrShed
04-27-2005, 03:39 PM
Hi guys,
I'm trying to draw using Graphics2D on a Java JPanel. Actually its a ImagePanel - a class ive 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 im drawing. Here is the code for the paint in the jpanel(if anyone needs me to post other code let me know):
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 ive tried writing directly to the g Graphics, but that doesnt work either. "image" is just a BufferedImage storing the JPEG and whatever else I want to have drawn(in theory!).
Any help would be appreciated
I'm trying to draw using Graphics2D on a Java JPanel. Actually its a ImagePanel - a class ive 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 im drawing. Here is the code for the paint in the jpanel(if anyone needs me to post other code let me know):
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 ive tried writing directly to the g Graphics, but that doesnt work either. "image" is just a BufferedImage storing the JPEG and whatever else I want to have drawn(in theory!).
Any help would be appreciated