Discussion:
GUI App Overriding paintComponent - GUI generated using IDE?
robben
2008-11-13 20:26:13 UTC
Permalink
Hi,



I have a simple question, I’m currently developing a GUI app using Java. It mainly consists of a main form (JFrame) a couple of texboxes and three JPanel’s which I add graphics to.



I have created the GUI form using the Netbeans IDE including the JPanel’s. What I would like to do is when I add something to each of the JPanels I would like to call repaint() and then for it to call the paintComponent() method which I override and then in this method I add the image I have created onto the JPanel. I do this for all three JPanels.



At the moment I have four classes. The first class lets call it MainForm is the class generated by NetBeans for the GUI objects. The three further classes are for each one of the JPanels. In these classes I have a overridden the paintComponent() which is called when I call repaint from a separate function in the class.



The problem I have is that the paintComponent() method is never called for any of the three JPanels. Lets say that one of the JPanels is called myJPanel which is in my MainForm class generated by NetBeans.

I have a myJPanel class which has a function which creates the graphic and then calls repaint and which then should call paintComponent(). But it does not work, would anyone know how I can get this working?





Thanks in advance for your help. :)
Pavel Pribyl
2008-11-14 14:48:36 UTC
Permalink
Hi.

It is hard to tell where the problem is, some code sample would be great.
Especially the repaint method, but also the method that creates graphics and
calls the repaint method. Could you please post it here?

Thanks

Btw, have you tried debugging the project? I would suggest placing several
breakpoint on the method calls and watching the behaviour of the program.

Best regards
Pavel Pribyl
Post by robben
Hi,
I have a simple question, I’m currently developing a GUI app using Java.
It mainly consists of a main form (JFrame) a couple of texboxes and three
JPanel’s which I add graphics to.
I have created the GUI form using the Netbeans IDE including the
JPanel’s. What I would like to do is when I add something to each of
the JPanels I would like to call repaint() and then for it to call the
paintComponent() method which I override and then in this method I add the
image I have created onto the JPanel. I do this for all three JPanels.
At the moment I have four classes. The first class lets call it MainForm
is the class generated by NetBeans for the GUI objects. The three further
classes are for each one of the JPanels. In these classes I have a
overridden the paintComponent() which is called when I call repaint from a
separate function in the class.
The problem I have is that the paintComponent() method is never called for
any of the three JPanels. Lets say that one of the JPanels is called
myJPanel which is in my MainForm class generated by NetBeans.
I have a myJPanel class which has a function which creates the graphic and
then calls repaint and which then should call paintComponent(). But it
does not work, would anyone know how I can get this working?
Thanks in advance for your help. :)
--
View this message in context: http://www.nabble.com/GUI-App-Overriding-paintComponent---GUI-generated-using-IDE--tp20491030p20501838.html
Sent from the Netbeans IDE Users mailing list archive at Nabble.com.
Loading...