• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 need a new interior decorator. This tiny ad just painted every room in my house purple.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic