Results 1 to 4 of 4
  1. #1
    bigjo is offline Member
    Join Date
    Jul 2011
    Posts
    27
    Rep Power
    0

    Default repaint() and revalidate() doesn't work in my JContentPane

    Hi,

    I have to make a game (connect4) for school. We have to use the observer-observable pattern in our game. So when I put a chip on the board the model will change and in a update() method the view of my board have to change. The observer-observable pattern is correct, because when I put my boardview in a JDIalog it opens and the new boardview is shown, but in this method I wanted that the viewBoard of my JContentPane is updated, but it isn't.

    I tryied with:
    jContentPane.revalidate()
    and
    jContentPane.repaint()

    It only work if I put:
    Java Code:
    viewBoard=null;
    jContentPane.add(getBoardGame(indexColPlayChip),BorderLayout.CENTER,1);
    jContentPane.revalidate();
    But that is not really the way to do, because I always will but my viewBoard to null and recreate a new instance of the object ViewBoard. Normally it is not really the way to go, because the viewBoard is the last version of my board.

    more details: viewBoard is created in a new class that extends a JPanel, and it is added to my JContentPane in my JFrame.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: repaint() and revalidate() doesn't work in my JContentPane

    I'm not sure if you've posted enough information to allow us to be able to answer your question.

  3. #3
    bigjo is offline Member
    Join Date
    Jul 2011
    Posts
    27
    Rep Power
    0

    Default Re: repaint() and revalidate() doesn't work in my JContentPane

    I have a model that extends observable and a view (in swing) that implements observer. When my model change, it call the update() method in my view. But it doesn't repaint it. I tried repaint() and revalidate(), but it doesn't work. If I put in the update() method the "new view" in a JDialog it show me the right new view. So I am sure it is correct. But when I put in the update() that it has to repaint it on the ContentPane, it doesn't work.

    So my question why does it repaint itself right in a new JDialog, but not in the ContentPane?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: repaint() and revalidate() doesn't work in my JContentPane

    Hopefully someone else will be able to help you, but I'm afraid that I don't have even a wild guess based on the information presented, other than that you've got a bug somewhere in code not shown.

Similar Threads

  1. Repaint calling Statement Doesn't Work in my code ?
    By nitin_daviet88 in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-24-2010, 03:09 PM
  2. Replies: 6
    Last Post: 06-16-2010, 06:03 AM
  3. repaint class doesnt work anymore... dunno why..
    By Addez in forum New To Java
    Replies: 9
    Last Post: 11-07-2009, 09:10 PM
  4. Why doesn't this work?
    By Corder10 in forum New To Java
    Replies: 1
    Last Post: 07-04-2009, 10:33 PM
  5. mouse click do not work after repaint
    By nobody in forum Java 2D
    Replies: 8
    Last Post: 12-07-2008, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •