File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes why does my viewport gets accumulated? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "why does my viewport gets accumulated?" Watch "why does my viewport gets accumulated?" New topic
Author

why does my viewport gets accumulated?

mahendra singh dhoni
Greenhorn

Joined: Mar 30, 2012
Posts: 5

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

learn each Java library|new to java?|download java editors(other than NetBeans)|all java standards|(for fun)my need for speed most wanted car
Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 175

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.


Please correct my English.
mahendra singh dhoni
Greenhorn

Joined: Mar 30, 2012
Posts: 5

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

Joined: Jul 19, 2011
Posts: 175

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

Joined: Mar 30, 2012
Posts: 5

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

Joined: Jul 19, 2011
Posts: 175

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

Joined: Oct 27, 2005
Posts: 19784
    
  20

Whenever you override paintComponent, the first call should be super.paintComponent(g). You're missing that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mahendra singh dhoni
Greenhorn

Joined: Mar 30, 2012
Posts: 5

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

Joined: Jul 19, 2011
Posts: 175

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does my viewport gets accumulated?