CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    15

    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.

    Thank you, any help appreciated greatly.

    -Naemi

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Oct 2010
    Posts
    15

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured