• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

fluctuation

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It shouldn't do that. Could you show us your code ? make sure you use the code tags.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79653
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove repaint(), as Michael already said ...
 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 258
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
......
[MG]Removed hijack
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic