I have a custom Swing component to draw a mathematical matrix, which inherits from JPanel. It has a few sub components (x labels, y labels, main body of values), and isn't intended to be used as a container by the GUI builder.
If I copy and paste it into another jpanel, it is correctly displayed in the form editor, and it correctly appears in the "// Variables declaration - do not modify" section of the java file. However, the initComponents method is not updated, so the component is never initialised. Furthermore, once the component is added Netbeans gives up altering the auto generated initComponents code, even if I add standard components.
Any ideas why this is?
This is the full code for the class, I have commented out two lines which draw the matrix brackets as they depend on another class:
My rec: don't use NetBeans to generate Swing source code. Instead create your own main Swing program and place your JPanel into it. You'll have much more flexibility and will learn much more.
Anyway, I"m not a NetBeans pro, but I don't think that it can work the way you are trying to make it work. You can work around this by placing your JPanel manually into an already existent NetBeans JFrame or JPanel, but you'll probably have to make sure that your JPanel object's initialization code is called. From the pros and amateurs I've spoken with, most avoid NetBeans code generation as it produces very ugly code that can be difficult to maintain.