Graphics Look "Choppy" After Scrolling

A

Adam Polt

Hello!

I have implemented a class which extends JPanel in which I've
overridden PaintComponent() to visualize a tree (or graph) using the
Graphics2D package. I've put this into a jScrollPane, because the
tree is typically bigger than the screen will allow. The graphics
work nicely, but once the panel is scrolled, it "chops up" the image
(on the part that was originally not shown.)

I was wondering if anyone knew of a simple (or not simple, but simple
is preferable, obviously) way to fix this problem.

Thanks for your help!

-Adam
 
A

A. Bolmarcich

Hello!

I have implemented a class which extends JPanel in which I've
overridden PaintComponent() to visualize a tree (or graph) using the
Graphics2D package. I've put this into a jScrollPane, because the
tree is typically bigger than the screen will allow. The graphics
work nicely, but once the panel is scrolled, it "chops up" the image
(on the part that was originally not shown.)

I was wondering if anyone knew of a simple (or not simple, but simple
is preferable, obviously) way to fix this problem.

Thanks for your help!

As an initial experiment, invoke

getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE)

on the JScrollPane. If that eliminates the "chopping up" of the portion
of the JPanel exposed by scrolling, and you are not concerned about
scrolling performance, then you are done.
 
D

Daniel Pitts

Hello!

I have implemented a class which extends JPanel in which I've
overridden PaintComponent() to visualize a tree (or graph) using the
Graphics2D package. I've put this into a jScrollPane, because the
tree is typically bigger than the screen will allow. The graphics
work nicely, but once the panel is scrolled, it "chops up" the image
(on the part that was originally not shown.)

I was wondering if anyone knew of a simple (or not simple, but simple
is preferable, obviously) way to fix this problem.

Thanks for your help!

-Adam

It very well could be that you are rendering from the wrong thread.
Make sure you are following the single-thread-access idiom used in
Swing.
 
A

Adam Polt

As an initial experiment, invoke

getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE)

on the JScrollPane. If that eliminates the "chopping up" of the portion
of the JPanel exposed by scrolling, and you are not concerned about
scrolling performance, then you are done.

This seems to fix the problem. Thank you very much!

-Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top