aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drawing on a JPanel fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drawing on a JPanel fails" Watch "Drawing on a JPanel fails" New topic

Drawing on a JPanel fails

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 302
I am drawing strings on a JPanel after I draw the image of a JPG. The paint component method is

I first draw the image of the JPG and this is working; then I call drawOnGlassPane to draw entered strings. Initially, I was drawing on the glass pane of the parent but since it didn't work I tried the graphics of the JPanel

The line "graphics.drawString(enteredText, xCoordinate, yCoordinate);" is being executed.

Your help will be greatly appreciated,
Alejandro Barrero
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2097
I doubt it is the problem but you should not be using drawImmediately inside the paintComponent(() method.

Post your SSCCE that demonstrates the problem.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 302
Thanks Rob. No that's not the problem. It is a weird problem with Eclipse or MyEclipse, because the code works fine in another workspace or project. I am writing to them. I DON'T KNOW HOW TO SET THIS TO RESOLVED.
Darryl Burke

Joined: May 03, 2008
Posts: 4523

Alejandro Barrero wrote:No that's not the problem.

Even if it's not *the* problem, it most certainly is *a* problem.

To repeat what Rob said: You should not be using drawImmediately(...) inside the paintComponent(...) method

luck, db
There are no new questions, but there may be new answers.
It is sorta covered in the JavaRanch Style Guide.
subject: Drawing on a JPanel fails
Similar Threads
Mouse and Key Listeners don't work on JPanel
A conundrum with seting Graphics font size
JPanel paint component called many times
Problem with ImageIO.write
Aspect ratio-preserving image scaling, drawing and infinite loops