Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

NetBeans Form Builder and using paintComponent method()?

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
[1053 byte] By [shauntck] at [2007-11-11 7:39:12]
# 1 Re: NetBeans Form Builder and using paintComponent method()?
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?
Joe Beam at 2007-11-11 22:37:41 >
# 2 Re: NetBeans Form Builder and using paintComponent method()?
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
mnuttall at 2007-11-11 22:38:46 >
# 3 Re: NetBeans Form Builder and using paintComponent method()?
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:
sjalle at 2007-11-11 22:39:45 >