Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JInternalFrame JPanel getGraphics() is null

416044Dec 9 2006 — edited Dec 10 2006
I changed my application that it uses now a JDesktopPane and JInternalFrame instead of just JFrames. My JInternalFrame has a JPanel as the content pane as it overwrites paintComponent() to draw an image. This works for JFrame but the same code in JInternalFrame gives me a NullPointerException in the overwritten paintComponent() because the result of getGraphics() is null!

When I debug my code, I see that getGraphics() returns null - but the strange thing about it is: if I jump back to the start of the paintComponent() (with Eclipse 'DropToFrame' function), getGraphics() returns an object! So, when I debug the code, set a breakpoint at getGraphics() and rerun the method, the second call of getGraphics() returns the graphics object (and the code continues fine) ... so I worked around this problem with
while (g == null) {
    g = getGraphics();
}
this works but has the potential of an indefinite loop. :-(

Is there something different with JInternalFrame?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2007
Added on Dec 9 2006
3 comments
316 views