• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why does my viewport gets accumulated?

 
mahendra singh dhoni
Greenhorn
Posts: 5
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've drawn a graph which has a dimension of (63375,720) using JPanel
I mean, my public class extends JFrame which contains a paintComponent(Graphics g)

My object name is ReadPlatInstance

I've set the preferred size of my object to

I've added it to a JScrollPane


I've set my pane size to my screen size


I've added the pane to a frame


I've packed the JFrame


It runs well until I scroll the bar
but when I scroll the bars, the incoming lines of my graph gets accumulated over the old lines.
I've to do this for my project work. submission date is coming very soon. (thanks for reading this).

these are my outputs:
before scrolling:

after scrolling:


regards
dhilip
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect you use double buffering and forget to clear the buffer or something like that.
Without a small main program showing the problem its not likely we might be able to help.
 
mahendra singh dhoni
Greenhorn
Posts: 5
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manuel Petermann wrote:I suspect you use double buffering and forget to clear the buffer or something like that.
Without a small main program showing the problem its not likely we might be able to help.


hi,,
this is my code



my input file consists of values like this..
"0.000010" " +0.053"
"0.000020" " +0.050"
"0.000030" " +0.053"
"0.000040" " +0.050"
"0.000050" " +0.053"
"0.000060" " +0.053"
"0.000070" " +0.050"
"0.000080" " +0.053"
"0.000090" " +0.053"
"0.000100" " +0.053"
"0.000110" " +0.053"
"0.000120" " +0.053"
"0.000130" " +0.053"
"0.000140" " +0.053"
"0.000150" " +0.053"
"0.000160" " +0.050"
"0.000170" " +0.050"

it has 63375 values in a notepad.

EDITED to add: this is my input file: uploaded file(filename:seat130apg.txt) (1.4mb) thanks

regards
dhilip
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said you need to clear your buffer before you draw.
Swing is not thread save so you as well need to do all of your drawing code in the event dispatch thread (edt).#
There are other things you can improve but that are the main two reason your code might not work.
 
mahendra singh dhoni
Greenhorn
Posts: 5
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manuel Petermann wrote:As I said you need to clear your buffer before you draw.
Swing is not thread save so you as well need to do all of your drawing code in the event dispatch thread (edt).#
There are other things you can improve but that are the main two reason your code might not work.


hi, thank you very much
could you tell me out, what is the specific method to be used? or what should be imported?

edited to add: how do we clear our buffer?


regards
dhilip
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You simply need to clear the rectangle in the area where you would like to draw. If you don't know where you are drawing you simply clear the whole graphics2d.
No I am not getting clearer than that. Its in the Api.
For the Event dispatch thread, read Threads and Swing.
No I am not getting clearer either.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you override paintComponent, the first call should be super.paintComponent(g). You're missing that.
 
mahendra singh dhoni
Greenhorn
Posts: 5
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Whenever you override paintComponent, the first call should be super.paintComponent(g). You're missing that.


oh my god thank you very much, now my problem is solved.

regards
dhilip
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry didn't got that covered.
My solution was more of a dirty hack i guess...
The part with the thread may become a problem still.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic