If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Netbeans custom components that preview nicely?

Hi,
This has been bugging me for a while, I'm using a JPanel to render some custom graphics output (a 2D plot) and I want this custom JPanel, or any similarly-designed component, to preview nicely in netbeans. My problem is netbeans seems to only do a very limited initialization and maintenance of components when they are in the layout.

From what I can tell, in design mode the only method that's called is initComponents(), so the constructor doesn't get called which makes it very hard to initialize a component properly so it's not blank in design mode. Using field initializers seems to work and also if I add it to another component that calls the constructor from it's own initComponents() method works too so I'm ok with this, but my problem is that once it's initialized I can't figure out how to get the state updated.

In design mode components are constantly stretched and I want them to react to that. So for instance if I extend a JPanel that paints a border around itself then I want to see that border change to fit the panel as I stretch it in design view. Does anyone know whether netbeans/matisse emits any events or provides any other way to have components draw themselves properly when designing forms? I'd really like to know, this isn't just a cosmetic issue, especially with complex layouts it really matters whether you can get some idea of what a component is going to look like when it runs.

Re: Netbeans custom components that preview nicely?

You would be better off posting on a NetBeans forum as this is an IDE issue and not a Java issue.

Have you tried reading the developer documentation, I'd be surprised if this sort of situation wasn't documented?

From what I can tell, in design mode the only method that's called is initComponents(), so the constructor doesn't get called which makes it very hard to initialize a component properly so it's not blank in design mode.

If it doesn't call a constructor how does it create an object to call initComponents() on? It may be that it's not calling the constructor you are using to initialise the component but it must be calling a constructor, probably the default (no argument) one.

BTW where does initComponents() come from, it's not part of the Swing component hierarchy.

Re: Netbeans custom components that preview nicely?

initComponents() is autogenerated by netbeans, it's a method that does the work of adding everything to the component and setting all the properties. But you are right, I don't know what I was thinking, it has to call the constructor -- anyway, I fixed my code, I think it was just an issue with the order in which things were being initialized. Netbeans puts initComponents() in the default constructor and I was putting my initialization code afterwards, which works most of the time but this time it didn't so I got confused. I should have just tested it with a couple small forms -- tried it today and it all made sense. Thanks for helping anyway.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.