Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fluctuation

 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salam,

I have drawn a graph in java in paintComponet method which is repainted by using repaint method...

But my problem is that my GUI fluctuates...

How can i remove that fluctuation???

Please tell me some suggestion???
 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shouldn't do that. Could you show us your code ? make sure you use the code tags.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The right way to do custom painting in Swing:
http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to GUI forum.

By "fluctuates" I presume you mean "flickers"?

Go into the API for whichever component you are painting on, and have a look at its constructors. You will probably find an overridden one with a boolean called doubleBuffered or something similar. Try putting "true" in that constructor. That might help.
 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Campbell,

I am not using the buffer for painting.
I am drawing a bar graph on x and y axis..
The graph gets the axis values from user and draw the graph bars one by one...

When first bar appears that is well but when second to onwards bars appear,

The screen flickers due to repaint method...

My question is that:

How can i get rid of that flickering???
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't possible to guess what you might have done wrong from your description. To get better help sooner, post a SSCCE* that clearly demonstrates your problem.

* http://mindprod.com/jgloss/sscce.html
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the area is large what your program is painting then use buffering as recommended before, or call repaint(Rectangle) to repaint only renewing area (if it aint the whole area)
 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code of the graph...

Do follow the constraints wriiten on the JFrame...

And then post me the code which is anti-flickered...

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you know what this does
repaint();
when called from paintComponent()?
 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,
It repaints the screen...
But did you execute my program???

If yes,
then what is the solution???
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> It repaints the screen...

which calls paintComponent(..)
which contains repaint()
which calls paintComponent(..)
which contains repaint()
which calls paintComponent(..)
which contains repaint()
which calls paintComponent(..)
which contains repaint()
which calls paintComponent(..)
which contains repaint()

do you now understand?
 
Rok Štelcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove repaint(), as Michael already said ...
 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call repaint() inside the paintComponent() method because repaint() calls paintComponent(). What you should do is either create a thread, either use a listener event.

I wrote you a quick program so you can understand:

This should clear things up.
 
vijay jamadade
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
......
[MG]Removed hijack
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay,
I have removed your thread hijack. Please post your question in a new thread.
http://faq.javaranch.com/java/UseOneThreadPerQuestion
 
Muhammad usman shad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Parvan Alexandro!!!
Thank you very much...
You told me to solve my problem using thread...
I did that yesterday...
I have solved my problem...

Again thanks alot...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic