This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes fluctuation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "fluctuation" Watch "fluctuation" New topic
Author

fluctuation

Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30
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

Joined: Dec 10, 2009
Posts: 115
It shouldn't do that. Could you show us your code ? make sure you use the code tags.


"Quoting yourself is stupid" - Me
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4530
    
    5

The right way to do custom painting in Swing:
http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38436
    
  23
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

Joined: Jan 06, 2010
Posts: 30
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

Joined: May 03, 2008
Posts: 4530
    
    5

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

Joined: Dec 13, 2008
Posts: 112
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

Joined: Jan 06, 2010
Posts: 30
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

Joined: Jun 09, 2003
Posts: 4632
do you know what this does
repaint();
when called from paintComponent()?
Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30
Yes,
It repaints the screen...
But did you execute my program???

If yes,
then what is the solution???
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Nov 03, 2009
Posts: 101
Remove repaint(), as Michael already said ...


SCJP, SCWCD
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
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

Joined: May 12, 2008
Posts: 240
......
[MG]Removed hijack


Regards, Vijay Jamadade.
( Nothing is Impossible.)
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Vijay,
I have removed your thread hijack. Please post your question in a new thread.
http://faq.javaranch.com/java/UseOneThreadPerQuestion

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30


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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: fluctuation