I'm using drawLine()
and friends to paint a graph onto a JPanel
. There are tens of thousands of points to graph, so it takes 3-5 seconds. I want to have a viewport, like the blue one illustrated below, over the graph.
I would like this viewport to be updatable, as I have a MouseMotionListener
on the JPanel
that the graph is on. The problem is, if I redraw the viewport (the square) as it is now, (using drawRect()
), I have to redraw the entire graph, which isn't desirable.
I've read some about GlassPanes, which may be useful for solving this problem, but they evidently are a part of JFrames
, and not JPanels
. (I have this panel along with other components inside of a JFrame
already.)
What would be a nice way to handle this, staying in Swing and being efficient?
For what it's worth, I'm actually coding in Clojure, but that shouldn't change anything here.
Thank you very much!
Isaac