• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
a wee bit from the empire
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic