2

I'm creating new app in Intellij IDEA 13.1.4 Community Edition

I can run my app in IDE, but, when I create jar, after execute I get error:

java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:620)
at javax.swing.JDialog.setContentPane(JDialog.java:1045)
at MainDialog.<init>(MainDialog.java:39)
at MainDialog.createAndShowUI(MainDialog.java:193)
at MainDialog.access$1200(MainDialog.java:13)
at MainDialog$13.run(MainDialog.java:184)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

I have tried to search on google/stackoverflow

and attached links in last post

Here is my sample code for MainDialog.java

    public static void main(String[] args) {

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            createAndShowUI();
        }
    });
}

private static void createAndShowUI() {
    System.out.println("Start");
    JFrame frame = new JFrame("rConnect");
    try {
        frame.setContentPane(new MainDialog().getContentPane());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (IllegalComponentStateException e) {
        e.printStackTrace();
    } finally {
        frame.pack();
        frame.setVisible(true);
    }
    System.out.println("Finish");
}

and here is my build.gradle

apply plugin: 'java'
apply plugin: 'application'

mainClassName = 'com.test.rconnect'
version = '0.1'
sourceCompatibility = 1.7
repositories {
    mavenCentral()
}



jar {

    baseName = 'rConnect'
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    from { configurations.compile.collect { zipTree(it) } }

    manifest {
        attributes 'Implementation-Title': 'rConnect'
        attributes 'Implementation-Version': version
        attributes 'Main-Class': 'MainDialog'
    }
}

sourceSets {
    main {
        java {
            srcDir 'src/main/java'
        }
        resources {
            srcDir 'src/main/resources'
        }
    }
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.apache.commons:commons-lang3:3.3.2'
    compile 'org.apache.commons:commons-io:1.3.2'
    compile 'commons-logging:commons-logging-api:1.1'
    compile 'org.ini4j:ini4j:0.5.2'

}

I'm also experiencing strange behaviour of IDE

When I do clean > run app, it is running without problem.

When I do jar > run app, it crash with same error, until I do clean > run.

Any help ? Thank You.

Community
  • 1
  • 1
Coudy
  • 127
  • 2
  • 13
  • Did you check if the jar if it contains all the resources? – morpheus05 Aug 11 '14 at 13:40
  • @morpheus05 , as far as I can tell, yes. there are unpacked resources for froms-rt.jar, asm4-all.jar, jdom, etc... I don't know, what should I check. btw. here is list of compiled libs added to project: asm4-all.jar, forms_rt.jar, javac2.jar, jdom.jar – Coudy Aug 11 '14 at 19:48

1 Answers1

7

I had the same problem and I've found the answer in your first link:

How to launch swing app with jetbrains layouts in Netbeans

http://www.jetbrains.com/idea/webhelp/gui-designer.html

So, use Java source files instead of Binary class files in GUI Designer and add this dependency to your gradle script:

compile 'com.intellij:forms_rt:6.0.5'
Community
  • 1
  • 1
Zoltan Febert
  • 471
  • 5
  • 9