Click to See Complete Forum and Search --> : NetBeans Form Builder and using paintComponent method()?


shauntck
01-04-2006, 06:53 AM
Hello everyone. I'm a little new to NetBeans so forgive me if this is an easy question but for the life of me I can't seem to figure this out. Anyways, I'm trying to use the form builder in Netbeans and I want to include a JPanel and override the paintComponent method do so some drawing. So, If I include the Standard JPanel I'm not inheriting from it and can't override the paintComponent method. However, if I try and create a JavaBean class that inherits from JPanel and overrides the paintComponent method and add it to the palette... it is invisible when I go to add it to the form.

This is really stumping me as to how I can override the method and yet still use the Form Builder...

Any ideas? I also noticed you could add a AWT Canvas class but I'm confused. Why would you add a Canvas if you don't have the paint method()? Am I missing something obvious or what because it seems like too simple a task to be having such a big problem.

Thanks for your help in advance!
-Shaunt

Joe Beam
01-05-2006, 01:30 AM
Never used a form builder for Java. I've tried some plugins for eclipse, but I thought it was easier to do Swing by hand. Just make a class like...

public class MyCanvas extends JPanel{
void paintComponent(Graphics g){

}
}

Then add it to your frame by hand. What do you need the form builder for?

mnuttall
01-05-2006, 01:38 PM
I doubt hit has to do with Netbeans itself. Check out the following for help.

http://java.sun.com/docs/books/tutorial/uiswing/14painting/index.html

sjalle
01-07-2006, 11:19 AM
One quick & dirty solution could be to just use the form builder using a plain JPanel first, then when the formbuilding is done you just step into the code and replace the JPanel with your JPanel extension.

AND...
Yes, I suspect that NetBeans will get trouble if you return to the formbuilding after the panel replacement, its a dirty solution, almost a hack... :cool: