Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Why does the JFrame not paint itself? It appears transparent.

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This seems like a nice forum, I hope you guys can help me with this problem I'm seeing that I just can't figure out myself. I will try to describe it in short:

* In Java i have made a ExceptionHandler class, an object will be created of it whenever a catched Exception occurs.

* The ExceptionHandler's constructor first closes all other JFrames using "Window.getWindows()".

* Then it sets a global variable "appRunning" to false, making all other threads exit themselves.

* After that it creates a object of a ErrorWindow class, the ErrorWindow extends JFrame and simply displays the Exception's message.

* Then the ExceptionHandler enters a loop where the thread sleeps, this will lock the thread until the ErrorWindow has been closed.

* When the ErrorWindow is closed the ErrorHandler notices this, exits the loop and shuts down the application.

This worked well for a lot of tests, except when a thread in the application throws ("Address already in use: JVM_Bind") when it cannot bind a Socket. The thread then creates a ErrorHandler object in it's IOException catch.

What happens is that the ErrorWindow opens (shows itself, the title bar + icon) but the ErrorWindow does not paint itself.

* I tried overriding it's "public void paint(Graphics g)"-method to print out something when called, and as suspected it does not recieve any calls.

It would seem that the JFrame's thread does not start when I use "setVisible(true)" in the ErrorWindow's constructor. The window can't be closed either by clicking [X] or hitting Alt+F4. All this without a new exception thrown.

So now I ask: Why does the JFrame not paint itself?

What reasons could there be. I have attached a picture of the ErrorWindow when it's launched but not painted (the yellow stuff is just to hide the JFrame's title). I have resized the window in the picture and moved it down a bit so that you can clearly see it's behaviour.

* I have tried commenting out the "Window.getWindows()" and "appRunning" part, meaning that the application didn't close all other windows and the other threads didn't exit themselves before the ErrorWindow is created. Still the same results, and I got no new Exceptions.

* The ErrorHandler is not used for exceptions catched inside itself, so this shouldn't be an issue of infinite recursion.

Thank you for any helpful thoughts, I'vve been working on this for quite some time now but I'm not getting any wiser.
[Thumbnail for screenshot.png]
The window is not displaying correctly. I have resized it and moved it down a little to the right so that its behaviour can be clearly seen.
Mark Johansson
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After som efurther testing I am now seeing some errors being printed at random, sometimes they are short, sometimes long. Other times they aren't printed at all. They always prints before the ErrorWindow is created, sometimes before the following code, sometimes during:

Here's the short error that is printed sometimes:

And here is the long error that is printed sometimes:

I guess the error could occur in a window's thread when I am disposing of the window (that's the correct way of getting rid of it, right?). But sometimes the error happens before the for-loop (I know this simply by writing a sysout before the for-loop is entered).

Also, as said before: If I comment out the for-loop the ErrorWindow is still not displayed properly (looks just like it does when the for-loop is left uncommented).

And input?

Edit: Added a line of code I had forgotten about.
Mark Johansson
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved, the thing was that the windows opened before the Exception occured never had time to begin drawing themselves before the ErrorWindow opened and then stopped the thread. I'm not sure why they depended on the thread launching the ErrorWindow, but that was how it went. I think.

I changed ErrorWindow to a static class, then moved a method call inside a thread's run method so that all windows had the time to properly initiate themselves before the method I moved was called. The moved method created the client thread, which produced the Exception when a socket couldn't bind to a local port.

Glad that's over with. Thanks to all that could have helped but didn't make it in time!
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic