Re: Drawing with Extended JPanel Class

philju <[email protected]> Thu, 7 Aug 2008 06:47:30 -0700 (PDT)
Newsgroups gmane.comp.java.netbeans.user-interface
Message-ID <[email protected]>
Hi Wade,

Thanks for the response, I will remember where to post next time ;-)

Thanks for your advice, I have now moved the extended JPanel class back into
the ui project package, but this has now meant that the class doesn't appear
when I search for beans to add to the palette within the project folder and
the automatically created distribution JAR. But I am also unable to drag &
drop the class from the project manager onto the JFrame from the visual
design view.

My extended JPanel class doesn't have any dependencies on any other JARs or
libraries, only other JDK classes and one from the project. To test this I
reduced the class to a very minimal extension as below and am still
experiencing the same problem.

Cheers,
Phil

------------------------------------------------------------------------------------------

package ui;

import java.awt.Graphics;
import java.io.Serializable;
import javax.swing.JPanel;

public class LegendPanel extends JPanel implements Serializable {
    
    private String title;
    private String colour;
    private int min;
    private int max;
    
    public LegendPanel() {
        
    }
    
    public void paint(Graphics g) {
        
        super.paintComponent(g);
    }
    
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getColour() {
        return this.colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public int getMin() {
        return this.min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public int getMax() {
        return this.max;
    }

    public void setMax(int max) {
        this.max = max;
    }
}



Wade Chandler wrote:
> 
> ----- Original Message ----
> 
>> From: philju <[email protected]>
>> To: [email protected]
>> Sent: Tuesday, August 5, 2008 6:09:41 AM
>> Subject: Re: [nbui] Drawing with Extended JPanel Class
>> 
>> 
>> Hi Wade, 
>> 
>> Sorry for the mis-posting, I'm new to this forum! Thanks for replying
>> anyway...
>> 
>> I thought adding the bean to the palette might be essential, in which
>> case I
>> have an additional problem... 
>> 
>> Below is the code for my extended JPanel, and currently it resides in the
>> root - "default package" of the project source folder. I believe I've met
>> all of the JavaBeans requirements and as such NetBeans registers the
>> class
>> as a valid bean when attempting add it from the project folder using the
>> palette manager. I select the bean and the palette category, no message
>> is
>> generated which leads me to believe the process has been successful.
>> However, when I access the palette it isn't visible, even following a
>> refresh. 
>> 
>> Dragging the class from the project navigator onto the form for visual
>> development doesn't result in anything happening either. Any thoughts? 
>> 
> 
> Does this class have any dependencies in any other JARs or libraries other
> than Swing? Also, it is now recommended, after Java 1.4, to always use a
> package as it can cause different issues with different class loaders.
> Your problem might resolve itself if you don't have any dependencies and
> move your class into a package. Also, make sure you build the class before
> you try to drag it from the project window.
> 
>> Can I also ask if including a second, non empty constructor would violate
>> the JavaBeans coding convention? 
> 
> It will not. The JavaBeans specification itself doesn't actually enforce
> the default constructor in text I don't believe, however, with any
> specification is a reference API, and there are classes in that API
> (java.beans) which require default constructors to work with JavaBeans,
> and all other code does this as well, because it is the only easy way for
> instantiation without some type of bean factory standard or something
> along those lines. Regardless, as long as the usage of your class by the
> IDE or other JavaBean tools is not dependent upon this other constructor
> it is perfectly fine. I do this all the time, and then I can change the
> initialization code in NB to use my other constructor.
> 
>>Please let me know if you would prefer I
>> re-post this in nbusers. 
>> 
> 
> It's fine to finish up here, just please remember in the future. Thanks
> for the understanding here.
> 
> 
> Wade
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Drawing-with-Extended-JPanel-Class-tp18814353p18870889.html
Sent from the Netbeans - UI mailing list archive at Nabble.com.