File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes My panel object won't repaint(). Please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "My panel object won Watch "My panel object won New topic
Author

My panel object won't repaint(). Please help.

Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
Hello guys,

I have a panel object. inside it there is paint(Graphics g) method.

I want the object to repaint() itself after I update the int[][] variable inside it.

So I put the repaint() method right after I update the int[][] variable, but nothing happened. as if the repaint() method wasn't there.

How do I force the repaint() method so I can get the result instantly?

Btw, same result with the validate() method.

Thank you so much beforehand.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> How do I force the repaint() method so I can get the result instantly?

post a sample program of how you are doing it.
(just a frame with panel and button, actionlistener for the button
to contain your int[][] and repaint() code)
Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
post a sample program of how you are doing it.


This is how I do it:




What I want to do is regularly update the thearray[][] value using doPlots(int[][] thearray) method and directly display it in the panel.

Originally I am planning to use repaint() method to manually redraw the panel. But nothing happens. same with validate() method.

Is this problems is connected to the thread, because I use threads to keep changing the thearray[][] value?

Hopes this information helps.

Thank you and please help me.
Mike Guze
Greenhorn

Joined: Jun 09, 2007
Posts: 11
Hi,

did you check your values passed to "drawOval()"?

I use a Thread to set values and repaint a JPanel and there isn't problem. Are you sure what the oval with width=1 and height=1 isn't there?
Ashok Mor
Ranch Hand

Joined: Jul 17, 2007
Posts: 43
Hi Aji Tanaka,

Please change your "g.drawOval((thearray[0] / 6) + xcntr, (thearray[1][i] / 6) + ycntr, 1, 1);"

statement to "g.drawOval((thearray[0][i] / 6) + xcntr, (thearray[1][i] / 6) + ycntr, 1, 1);"




Ashok Mor
Ness Technology.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it does work, as you can see from this
(after stripping most of it - the stated problem being repaint() not called from doPlots())



you may notice you can copy/paste then click compile, click run and see it working.
I could not do the same with what you posted.
Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
Dear guys,

First of all, thank you for all of your effort to direct my problem.

But, sorry to tell you that the same problem still occurs.

This time, I have paste in this post the very program that causing the problem. If it is not too much of a problem, please take a look at those code. Feel free to copy-paste and Run the codes as it is.

This time I added 2 buttons on the left side of frame, one is for changing the background color into red and the other is for changing the background color into blue. This function also do not work. Maybe the problem is somehow has connection to the won't-repaint() problem.

Thank you so much for your time and efforts. Help me, please.

Aji Prasetyo
Ranch Hand

Joined: Jun 13, 2007
Posts: 65
Hello again,

Sorry for the trouble, but in connection of the problem that I am asking, I want to consult a possible solution.

since the mouse listener can detect the mouse action and repaint() the panel properly, is it possible to put the object listener on the thearray[][] object. I mean, when thearray[][] object receive new value, the object listener catch it and repaint() the panel properly as if mouse listener do.

Is there anyone knows how to do this?

Thank you for your attention. Please assist me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My panel object won't repaint(). Please help.
 
Similar Threads
update and repaint
paintComponent() troubles
repaint a perticular panel.
A simple animation doubt
Using Graphics in a BorderLayout