Search code examples
netbeansgroovygriffonswingbuilder

Griffon View Script Generated from NetBeans Not Showing


I developed a UI in NetBeans that I want to use in my Griffon application. I chose to do so because I don't have enough time to figure out how to get the screen laid out correctly using SwingBuilder. According to the book Griffon in Action, I basically just need to place the .java file created in NetBeans under the appropriate package in the src directory of my Griffon project and run the griffon generate-view-script command with the fully qualified class name of the .java class (it took me a while to figure out how to do that). It then generates a .groovy file in the views directory that contains some code wrapping the .java class to make it work with SwingBuilder. When I try to run this as-is, nothing comes up. There are no exceptions being thrown, but nothing shows up either.


Solution

  • As it turns out, the .java class contains a Main() method in which the visible property of the class (it is a subclass of JFrame) is set to true. The Main() method does not get called by SwingBuilder, so the visible property was never being set to true. To correct this, I just had to add visible: true to the parameters to the generated widget node like below.

    widget(new package.path.MyClass(), id: 'MyClass', visible: true)
    

    Once I did that, it came up just fine.