• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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: 74351
334
  • 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: 11445
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...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic