Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  repaint in a jpanel,big problem  (Read 712 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Member




Java games rock!


« Posted 2005-06-14 23:31:06 »

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!