• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel not displaying in JWindow splash

 
Todd Bruner
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple "splash" screen that says please wait in a JLabel. The JWindow appears but no text is show in it.

Here's the code:


Any pointers would be appreciated. Thanks.
Todd
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be you having some mistakes calling this class

try this code it works and shows the label




(peace)
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
omar al kababji wrote:try this code it works and shows the label

I'm concerned that you and the OP are not taking Swing thread safety into consideration. Better to use the Swing's very own splash screen, but if you can't use that, then make sure that all Swing calls are made on the EDT, and use a Swing Timer, not Thread.sleep(...):

 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'm concerned that you and the OP are not taking Swing thread safety into consideration


actually i just copied and pasted the code to test it, because for me it seemed that it was strange that the label didn't appear in the application ;)


(peace)
 
Todd Bruner
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pete:

I suspect you've identified my problem, unfortunately, I'm a little stuck on how to fix in the context of the larger app I'm working on.

I used the SplashScreen class you provided and when run stand alone it works. When I use it in my app, however, the JWindow appears but the JLabel is not visible. The problem must be with my stuff.

I want my app to work this way: User enters authentication information and presses a JButton "go". I want the splash screen to display because the app takes a while to start when it is loading the dataset that it operates on. Here's the relevant code from the button press action:



The IgidsGui implements runnable and the start method does:




Thanks in advance for your help...

Todd
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to execute the code the creates and shows the splash screen in a separate thread something like this


(peace)
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I recommend: First of all, do not execute a splash screen in a different thread as was suggested by someone else. This and all Swing code needs to go on one thread, the EDT. Period.

Second, and I suspect that this is the main problem, but it is your non-GUI time-intensive code that needs to be called in a background thread, that is the loading of the dataset. Perhaps you can load it from within a SwingWorker object. If this doesn't help, perhaps you could create a very small compilable program that demonstrates your problem. You could emulate the dataset loading by using Thread.sleep(3000), or create some busy work method. Best of luck.

Pete
 
Todd Bruner
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pete. I took your advise and it is working.

Todd
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!