Hi
My application creates a JFrame, and it adds my custom class that extends JPanel like this:
sceneEditorJFrame.getContentPane().add(new SceneTegnebrett(editorManager));
This works ok, but the problem is that this custom class, SceneTegneBrett wont repaint itself unless I use the mouse on the JFrame and resize it.
What is supposed to happen is, I pick an image with a FileDialog, and when this is done the “editorManager” object notifies the JPanel with an event. I know this works because I use System.out.println to see if the program gets into that method, and it does. The problem is that when that happens i want the JPanel to repaint itself with the new image. Even though i am calling repaint(); when it happens it doesnt reach the paintComponent(Graphics g) method. But when I resize the JFrame the paintComponent method is called and the JPanel paints itself with the new image.
Here is the code for the custom JPanel:
public class SceneTegnebrett extends JPanel implements SceneChangedEventListener, BackgroundChangedEventListener {
EditorManager editorManager;
/**
* @param scene
*/
public SceneTegnebrett(EditorManager em) {
editorManager = em;
editorManager.addSceneChangedEventListener(this);
editorManager.getCurrentEditingScene().addBackgroundChangedEventListener(this);
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawRect(0,0,20,20);
g.drawImage(editorManager.getCurrentEditingScene().getBackground(),0,0,null);
System.out.println("paintComponent()");
}
/* (non-Javadoc)
* @see com.esedit.manager.event.scenegui.SceneChangedEventListener#sceneChanged(com.esedit.manager.event.scenegui.SceneChangedEvent)
*/
public void sceneChanged(SceneChangedEvent evt) {
System.out.println("scenechanged event");
}
/* (non-Javadoc)
* @see com.eventyrskole.spillmotor.event.BackgroundChangedEventListener#backgroundChanged(com.eventyrskole.spillmotor.event.BackgroundChangedEvent)
*/
public void backgroundChanged(BackgroundChangedEvent evt) {
System.out.println("backgroundchangedevent");
repaint();
}
}
The method public void backgroundChanged is called, but when this happen the repaint() call doesnt seem to work. Atleast the paintComponent method isnt called.