Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Gregory
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic