I've been doing some development using Griffon lately. Griffon is a Grails like application framework for developing desktop applications in Groovy which lets you create Java Webstart applications without the hassle. It takes a clean MVC approach including nifty automatic binding of the model to the view. If you want to give Griffon a go, please have a look at the Quick Start guide.

I was looking for a solution to run the application I wrote in fullscreen mode. It took me a while to figure out how to do this. In the end it was quite simple.

Griffon offers a couple of hooks to execute code on specific states of the application lifecycle. The following hooks are availlable:

  • griffon-app/lifecycle/Initialize.groovy
  • griffon-app/lifecycle/Ready.groovy
  • griffon-app/lifecycle/Shutdown.groovy
  • griffon-app/lifecycle/Startup.groovy
  • griffon-app/lifecycle/Stop.groovy

I added the following code to the 'griffon-app/lifecycle/Ready.groovy' script:

GROOVY:
  1. import java.awt.GraphicsEnvironment
  2.  
  3. def graphicsEnvironment = GraphicsEnvironment.localGraphicsEnvironment
  4. def device = graphicsEnvironment.screenDevices.find{it.fullScreenSupported}
  5.  
  6. device?.setFullScreenWindow(app.appFrames[0])

The 'app' variable in the script is an implicit variable pointing to the actual application. Via this variable one can get access to all parts of the application; since I've just got one frame choosing was easy.

Haven't had the change to test the above on windows... but it works like a charm in OSX.


5 Responses to “Running your griffon application in fullscreen mode”

  1. 1 levi_h

    Lucky you... getting a Swing application to run full screen used to be quite difficult (see http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html).

  2. 2 peter

    @levi_h

    well that tutorial is exactly what I used to understand how the Swing part of the story works; is this an old-fashioned approach?

  3. 3 levi_h

    That's hard to say for The Java Tutorial - some of the parts really show their age. But if it's not, I wonder whether calling #setFullScreenWindow only will be enough. I mean, why all the code (in the tutorial) when all you need is a single statement?

  4. 4 peter

    well, you'll need to get hold of a device the call #setFullScreenWindow on. If you refactor all the boilerplate Java code to Groovy the above is what remains.

  5. 5 levi_h

    Yes, I understand that... I was actually thinking about active vs passive rendering and examples like http://java.sun.com/docs/books/tutorial/extra/fullscreen/example-1dot4/MultiBufferTest.java, which contain a whole lot more than a single setFullScreenWindow call. After reading a bit more, I see

    Feel free to use passive rendering if you just want a simple full-screen Swing or AWT application, but remember that paint events may be somewhat unreliable or unnecessary while in full-screen exclusive mode.

    which I remembered apparently.

Leave a Reply





About

Welcome to the weblog of Peter Maas. Here you'll find various posts related to stuff I like (like my kids and espresso) and stuff I do (like developing software).

JavaOne 2008 Pictures

konijn trouwauto overburen IMG_4556.JPG abandonned_factory flower IMG_4616.JPG IMG_4609.JPG golden_gate_warning_sign javone 2008 closing keynote IMG_4568 ketel_closeup plant IMG_4581 IMG_6124 IMG_1058 boottocht Stage being build in the nearby park War Room - Diagrams espresso danielle (bw)
View more photos >

Categories



Meld u aan voor PayPal en begin direct met het accepteren van creditcardbetalingen.