idea-IC, gradle and swing forms
Hi all, im trying to create gradle project with idea swing form, my build file:
'dev.null'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'dev.MainApp'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.intellij:forms_rt:7.0.3'
}
--
then i created very simple form with form builder:
public class MainForm {
private JPanel rootPanel; // rootPanel
private JButton button; // oneButton on form
public MainForm() {
JFrame frame = new JFrame("title");
frame.setContentPane(rootPanel);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(450, 300));
frame.pack();
frame.setVisible(true);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
});
}
}
and here launcher class:
public class MainApp {
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MainForm();
}
});
}
}
but everytime im tryin to launch app with 'gradle :run' i get NpE:
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:processResources UP-TO-DATE
:classes
:run
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JFrame.setContentPane(JFrame.java:698)
at dev.MainForm.<init>(MainForm.java:14)
at dev.MainApp$1.run(MainApp.java:11)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
// skiped
Does anyone know how to create gradle project with swing forms in idea?
Thanks.
Attachment(s):
sample.tar.gz
Please sign in to leave a comment.
To compile UI form you should call ant task javac2, see the example below:
build.xml
<project name="customcompiler" default="customcompile">
<property name="idea.home" value="/Applications/IntelliJ IDEA 15 EAP.app/Contents/"/>
<path id="compile.classpath">
<fileset dir="${idea.home}/redist">
<include name="annotations.jar"/>
<include name="forms_rt.jar"/>
<include name="javac2.jar"/>
</fileset>
</path>
<path id="classpath.uidesigner">
<fileset dir="${idea.home}">
<include name="lib/*.jar"/>
<include name="redist/*.jar"/>
</fileset>
</path>
<taskdef name="javac2"
classname="com.intellij.ant.Javac2"
classpathref="classpath.uidesigner"/>
<target name="customcompile">
<mkdir dir="build/classes/main"/>
<javac2 srcdir="./src" destdir="build/classes/main" classpathref="compile.classpath">
</javac2>
</target>
</project>
build.gradle
group 'sample'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'dev.MainApp'
sourceCompatibility = 1.7
repositories {
mavenCentral()
}
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'dev.MainApp'
}
task customrun << {
javaexec {dev.MainApp}
}
ant.importBuild 'build.xml'
task compileJava(overwrite: true, dependsOn: customcompile) {
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'com.intellij:forms_rt:7.0.3'
}
Also, see https://grahamedgecombe.com/blog/2013/04/03/using-intellij-ideas-javac2-in-gradle
(the discussion is here: https://youtrack.jetbrains.com/issue/IDEA-149668)
thanks for reply buddy, i found that blogpost already. actually im really wondered why jetbrains supply such weak gui form designer, next time i`ll avoid it in my projects.
thanks once again
I've run into a similar problem and tried to use the solution provided by Vassiliy Kudryashov, but it doesn't include the dependencies defined in the gradle build file when compiling.
Can anyone advise how to make this work? I'm trying to do a multi-project build, so I can't just include the libraries in the ant file.
Thanks.