I am having issues with the speed of the drawline
method of the Graphics class. I am using it to draw a line graph to the screen from a linked list. Once the list is large enough (around 150000 values) it takes a lot longer to loop through the entire list and redraw all the lines. I am wondering what I can do to improve the performance of the program either by optimizing the drawline
method, or abandoning it.
@Override
protected void paintComponent(Graphics g) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
Graphics2D scaledG = (Graphics2D) g.create();
g.dispose();
super.paintComponent(scaledG);
AffineTransform scaleTransform = new AffineTransform();
scaleTransform.scale(graphScale, 1);
scaledG.setTransform(scaleTransform);
scaledG.setColor(new Color(242,100,66));
for (Line line : lines) {
scaledG.drawLine((int)line.x1, (int)line.y1, (int)line.x2, (int)line.y2);
}
scaledG.dispose();
}