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 Lines disappear when scrolling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Lines disappear when scrolling " Watch "Lines disappear when scrolling " New topic
Author

Lines disappear when scrolling

Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
Hi all,
I am drawing lines on JComponent/JPanel wrapped in Jscrollpane (along with two JTables) the lines connect the rows of the left and right tables.

When I scroll down, the lines erased by the top part of the container,
So i tried to use the repaint method and now the lines disperses completely.

please advise


Here is the canvas:



And this is the ScrollBar listener:

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
There are so many ways to get into trouble with drawing that it's difficult to
know where to start with what you've presented.
Some comments:
Looks like you are using custom Point and Line classes. I wonder what's going on
in the Line class: could you be changing the line locations with each of the p1.setX(p1.getX() +...–type calls?

I experimented a bit with the getComponentGraphics method and it seems to
alter the graphics context, at least the color, during the drawing of the lines.
Maybe you are trying to draw only the parts of the lines that need re-drawing.
Swing will do this for you automatically (double–buffering).

The scrollPane will automatically repaint the graphics located within its view
extent.
Here's an idea:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lines disappear when scrolling
 
Similar Threads
Line delete problem in jpanel on mouse clicked
cannot manage layout in the frame
Drawing text inside a Graphics2D shape
How to save GUI in XML file and vice versa??
How to draw straight line instead of curved line??