Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ refusing to add custom component

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?

like image 351
Max Beikirch Avatar asked Jan 20 '13 14:01

Max Beikirch


2 Answers

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:

  • change project/module JDK to 1.6
  • in IDEA 12 it's possible to configure bytecode version per module, set it to 1.6
  • in Additional command line parameters field specify the following options: -source 1.6 -target 1.6
  • run IDEA under JDK 1.7 (applies to Windows and Linux, not recommended on Mac)
like image 186
CrazyCoder Avatar answered Sep 30 '22 19:09

CrazyCoder


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.

like image 28
Javaru Avatar answered Sep 30 '22 19:09

Javaru