6

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?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Max Beikirch
  • 2,053
  • 5
  • 25
  • 36
  • 1
    +1, since so solid reason given for the downvote, and to me the question looks authentic and genuine. – nIcE cOw Jan 20 '13 at 15:21
  • 1
    As an aside, `super(true)` is superfluous. Does IntelliJ require a no-arg constructor for custom components? – trashgod Jan 20 '13 at 15:30
  • 2
    Had you tried overriding [getPrefferedSize()](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#getPreferredSize()), and let it return some Dimension object like `return new Dimension(300, 300);`, might be your test class is added, though some layouts, will tend to return `0,0` as the size of the `JPanel`, if the size is not provided. Try to do this, might be it will work. – nIcE cOw Jan 20 '13 at 15:33
  • First of all - thanks for your comments and @GagandeepBali: Thanks for the upvote! I tried your idea but IntelliJ still doesn't display my 'test'-class. Interesting enough, it is not even added to the controls-hierarchy, where all the controls of a form are displayed. – Max Beikirch Jan 20 '13 at 15:55
  • @trashgod: Using a no-arg-constructor makes it easier as I do not have to provide the custom initialization. But I borrowed the idea of an arg-constructor to force IntelliJ to ask me for custom initialization. Sadly, it does not even do that. – Max Beikirch Jan 20 '13 at 15:56

3 Answers3

6

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:

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • Well, that's it. I am somewhat upset to see that IntelliJ does not run from 1.7 yet. Anyway, thanks for that detailed and helpful answer! – Max Beikirch Jan 22 '13 at 18:37
3

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.

Javaru
  • 30,412
  • 11
  • 93
  • 70
  • I invalidated the caches without success. :( – Max Beikirch Jan 20 '13 at 19:08
  • The idea with the log was a good one - but it doesn't help me. Maybe you can tell me, what's going on: The log says: blah blah.. java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) blah blah.. [ 89423] ERROR - com.intellij.ide.IdeEventQueue - Last Action: EditorEscape My JDK is 1.6.0_31. I'll try upgrading it and tell you whether it worked or not. Apart from that, I don't know what causes that error. – Max Beikirch Jan 20 '13 at 19:08
0

Make sure you compile the custom component and then click on Reload Custom Components button on the toolbar. That solved the issue for me.

Nufail
  • 1,588
  • 1
  • 17
  • 31