wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes Why does my component not play nice with Netbeans GUI editor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Why does my component not play nice with Netbeans GUI editor?" Watch "Why does my component not play nice with Netbeans GUI editor?" New topic
Author

Why does my component not play nice with Netbeans GUI editor?

James Gregory
Greenhorn

Joined: Jun 17, 2009
Posts: 2
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:

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

This is more of a Netbeans problem, rather than Swing code problem.
Moving it to the proper forum you might get more response.
...and welcome to the Ranch


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
jQuery in Action, 2nd edition
 
subject: Why does my component not play nice with Netbeans GUI editor?
 
Similar Threads
centralising characters
looking for a graphical representation
label in coordinates
way to rotate without using Graphics2D.rotate()
Rotating the Text in an Applet