views:

317

answers:

1

I'm creating a splash screen for a Java application using the SplashScreen class. The problem is that the position on multi-monitor systems is undefined. The documentation states "the position on multi-monitor systems is not specified - it is platform and implementation dependent". The application is going to be used solely on multi-monitor platforms, and I would like to ensure that it's always centered on one of the screens. Is there any way to achieve this? The application is going to be used on Linux only, so the platform is the same everywhere.

+1  A: 

Then don't use the builtin splash screen from Java 6. Create your own splash screen using your UI toolkit and position the window manually by calculating its size and the size of the available screens.

PartlyCloudy
I have tried this, and it works as long as I load the splash screen in a separate thread before I start creating the rest of my GUI. However, the last line of the code that loads my GUI breaks this. I invoke KeyboardFocusManager.getCurrentKeyboardFocusManager() .setGlobalCurrentFocusCycleRoot(pane); to make "pane" the focus cycle root, which I have to. But as soon as this line is added to the end of my GUI building code, the splash screen is only displayed as a gray square. That's why I aimed for the SplashScreen class instead (which I guess should be best practice to use anyway).
Bulgur
I think you can't get around when using the built-in splash screen. This is one of the disadvantages of the interoperability of a Java solution working on all OSes.But have you considered using SwingUtilities.invokeAndWait() in order to serialize GUI creation and processing for setting the splash screen upfront. There is also a couple of tutorials available howto create a AWT/Swing/etc. based splash screen.http://www.javaworld.com/javaworld/javatips/jw-javatip104.htmlhttp://www.randelshofer.ch/oop/javasplash/javasplash.htmletc.
PartlyCloudy
First: *do not manage swing components "in a separate thread."* They are meant to be updated only from the event dispatch thread, and you're probably getting the gray box for just this reason.
kdgregory
Second: splash screens are meant to cover the application startup time. Back when Java was used for applets, over a 56k modem, most of this startup time was spent downloading classes. In that world, a splash-screen loaded before the JVM makes a lot of sense. In today's world, it makes much more sense to create your own undecorated splash frame as soon as the app starts; the load time for basic Swing classes is a fraction of a second.
kdgregory