• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lines disappear when scrolling

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic