#1: I make a new JPanel Form, and override it's paintComponent() so that that the background always fills with yellow. Then I drag and drop this panel onto a JFrame form.
The problem: When I run the program, the JPanel doesn't become yellow. From the debugger it seems the overriden paintComponent() method is not being called.
#2: I make a new JPanel form, and add a method to it called 'testMethod()'. I drag and drop this panel onto a JFrame form.
The problem: I can't access testMethod() from the panel's reference (which is in the JFrame). This is even when I use "customize code" so that the declaration of the panel uses my new class rather than the superclass JPanel. When I explicitly cast the reference to my class' type, I can see testMethod(), but an exception is generated when run.
Any suggestions how to get round these problems and why they occur?
1. Post your code.
2. What IDE are you using?
3. What is a JPanel Form ?
4. What is a JFrame Form ?
Joined: Apr 09, 2009
JFrame Form class (Netbeans generated all of this code automatically):
JPanel Form class (Netbeans generated all of this code except for the overriden paintComponent() method):
I am using Netbeans 6.7.1.
The "Form" is the graphical interfaces Netbeans has, which you can drag and drop components onto and code is automatically generated.
In the code above, the paintComponent() method of the JPanel is overidden so it fills yellow. I coped this panel onto the JFrame, so when the program is run, the panel inside the JFrame should be yellow. But it is not changing colour.
I need to change the image during runtime, so I add a method to the above example that allows one to change the referenced image object. The problem is I cannot access this new method from the JPanels instance in the JFrame.
So for example, if I do this in pseudo-code:
If I drag and drop this JPanel into a JFrame, then I can't access the public method changeImage from that reference in the JFrame.