Can't override to paint on a JPanel

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't override to paint on a JPanel

Cryhavoc
I've created a nice NetBeans GUI with some radio buttons and a button control. It just needs to do a simple thing. Select a shape> select a color> click the button and render it on the panel. The specific size of the shape will be a randomly determined in the background.

However, before all that functionality is implemented I'm just trying to paint "Hello World" on the panel when the program is run. If I can just get it to that then, I'll know the process to do everything else. I've written another class to extend JPanel but no matter what I try I cannot get it to override the GUI panel.

So right now as I understand it. I need to use getContentPane and add an instance of the extended class to the JFrame. Outside of NetBeans I can use the name of an instantiated JFrame but IN NetBeans no matter what I try I cannot figure out how to add anything to the generated JFrame??

If I don't use NetBeans it works just fine so I just don't understand why it is soooo hard to do with NetBeans... Or is it just not possible at all with NetBeans?




Attachments:
http://forums.netbeans.org//files/gui_first_open_150.jpg

Reply | Threaded
Open this post in threaded view
|

Re: Can't override to paint on a JPanel

Eduard
Hello Cryhavoc,

Your question is not very clear for me.

What do you mean when you say it works outside NB? And what do you do
when you say it doesn't work in NB?

In general the way to write a text in a Java Swing componet is to add a
JLabel to a container such as a JPanel and then use setText to put some
text in it.

 From your picture I see that your code has created a window and added
the buttons and the drawing pad. Did you code this your self or was it
generated for you? In the latter case the generator has property for the
graphic object it places where you can specify the class to use. Either
way, there will be a variable in your code for the JPanel that is
(presumably) your drawing pad and you could add a new JPanel with an
overridden paint() method that handles painting the shapes.

I hope this helps
Cheers
Eduard

Cryhavoc wrote:

> I've created a nice NetBeans GUI with some radio buttons and a button control. It just needs to do a simple thing. Select a shape>  select a color>  click the button and render it on the panel. The specific size of the shape will be a randomly determined in the background.
>
> However, before all that functionality is implemented I'm just trying to paint "Hello World" on the panel when the program is run. If I can just get it to that then, I'll know the process to do everything else. I've written another class to extend JPanel but no matter what I try I cannot get it to override the GUI panel.
>
> So right now as I understand it. I need to use getContentPane and add an instance of the extended class to the JFrame. Outside of NetBeans I can use the name of an instantiated JFrame but IN NetBeans no matter what I try I cannot figure out how to add anything to the generated JFrame??
>
> If I don't use NetBeans it works just fine so I just don't understand why it is soooo hard to do with NetBeans... Or is it just not possible at all with NetBeans?
>
>
>
>
> Attachments:
> http://forums.netbeans.org//files/gui_first_open_150.jpg
>
>