Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2005

Tip: Looking for answers? Try searching our database.

Splash Screen Woes or Why doesn't setVisible(true) protect from setVisible(false)

Thread view: 
James Kimble - 28 Jul 2005 15:24 GMT
For the last week I've been tracking down a problem that has absolutely
made me
crazy. My program is a near real time GUI that monitors a piece of
audio equipment.
We upgraded to Java 1.5 recently and started getting a white screen up
startup.
Not every time mind you. My test machines seem to want to do it about 1
time in 100
while our field machines were doing it a lot more often. The background
processes
of the application would run fine but the GUI was just a blank screen
(white).

I finally tracked the problem down to the splash screen that would be
displayed
while waiting for certain synchronizations to occur. It seems that, on
some
occasions, the code that creates the splash JFrame and calls
setVisible(true) was
being followed by estVisible(false) a little too quickly for Java's
liking and the
empty JFrame (no message was displayed) would come up and stay up.

I'm posting primarily to see if maybe I'm missing something and there's
a problem with my code (see below) or, alternatively, if others have
encountered this problem
and what they did about it. I really dislike putting sleeps into a
program because
events are not properly synchronized in Swing but at this point I don't
know what
else to do (except drop the screen altogether).

These are the two methods. When called with a delay they work fine but
when called
one right after the other, I get a white screen about 3 times in 5.

////////////////////////////////////////////////////////////////

  public static void showMessageWindow(String msg)
   {
       synchronized (classLock)
       {
           if (messageWindow == null)
           {
               Dimension d =
Toolkit.getDefaultToolkit().getScreenSize();
               int w = d.width;
               int h = d.height;

               log.info ( "Creating window message panel of width " +
w +
                          " and height " + h);

               messageWindow = new JFrame();
               messageWindow.setUndecorated(true);

               messageWindowLabel = new JLabel();
               messageWindowLabel.setHorizontalAlignment (
                       SwingConstants.CENTER);
               messageWindowLabel.setFont(new Font("Dialog",
Font.BOLD, 16));
               messageWindowLabel.setForeground(Color.black);

               JPanel panel = new JPanel();
               panel.setLayout(new BorderLayout());
               panel.add(messageWindowLabel, BorderLayout.CENTER);
               panel.setBounds(0, 0, w, h);

               messageWindow.getContentPane().setLayout(null);
               messageWindow.getContentPane().add(panel);
               messageWindow.setBounds(0, 0, w, h);
           }

           log.info("Showing message window: " + msg);

           messageWindowLabel.setText(msg);

           messageWindow.setVisible(true);
       }
   }

   public static void hideMessageWindow()
   {
       synchronized (classLock)
       {
           log.info("Hiding message window");

           messageWindow.setVisible(false);
       }
   }

////////////////////////////////////////////////////////////////////
Thomas Weidenfeller - 28 Jul 2005 17:31 GMT
> Not every time mind you. My test machines seem to want to do it about 1
> time in 100
> while our field machines were doing it a lot more often. The background
> processes
> of the application would run fine but the GUI was just a blank screen
> (white).

Try Q4.3, Q3.1, and Q3.2 of the FAQ for a start. If that doesn't help,
study Q2.4, and the page link-to in Q2.4 extensively.

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

James Kimble - 28 Jul 2005 18:52 GMT
Thank you, this was very helpful.

The app is starting the window in one thread and then spawning a new
thread where the hide window method is called. I believe this is a
problem.
In addtion the setVisible(false) must not be called too quickly after
the setVisible(true). I found that a delay of 500 ms is enough but less
than that (on this platform at least) leads to a white screen that
persists and never
goes away.

Thank you again for the FAQ. It's very helpful.

James Kimble


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.