my problem is as follows: Assume that we have the following file:
package p;
import javax.swing.*;
public class test extends JPanel {
test(){
super(true);
}
}
I save the file and compile it. Now, in IntelliJ, I open a form and try to add test
to it. It won't work! I click 'Non-Palette Component', click on my form and in the dialog that open up, I type p.test
as my class name (IntelliJ even offers name completion here) and check 'create binding automatically'. After I click ok, nothing happens. But - if I take 'javax.swing.JButton' for the class name, it works. It's ridiculous. I don't see what I am doing wrong? Does test have to implement or override a certain function? Do I have to modify a path? Or should I just kick my PC out of my window?
java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0
The problem is that you have the project language level set to 1.7 and using JDK 1.7 to build it. IntelliJ IDEA is running under JDK 1.6 on your system and cannot load the custom component class that was compiled with the 1.7 language level.
Possible solutions to this problem:
-source 1.6 -target 1.6
Are you running the latest version of IntelliJ IDEA? The action you describe works for me in 11.1.5 and 12.0.2 (the latest versions for IDEA 11 and 12). There might be a bug in an earlier version. Also, since test
is a 'JPanel', are you selecting the "Is Container" option on the "Add Non=Palette Component". For the simple example you show, without this option selected, I do not get anything visible in the GUI designer when it is not selected in the "UI Designer" tool window. But you mentioned you do not even see it in the controls-hierarchy.
If you are at the latest version, I recommend you check the log (Help > Reveal Log) to see if there is an error in there that might shed some light on the issue.
Lastly, you can try invalidating the caches and restarting. (File > Invalidate Caches). It's possible there is some corruption that is causing an issue.
I would have added this as a comment to your question, but I do not have enough reputation points to do such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With