i am trying to draw some lines. Problem is about colors. For example. I have several lines of red color, and than i draw one line of blue color (or reversed). And sometimes, that lines those is more, is opaque for that last one.
I tried to make new color and set color with alpha composite 0.7 - for those more lines, and one color i left default - opaque (alpha 1.0). At first i draw more lines, and than last one. But that lines "overwrite" that one. Is there some solution to fix this problem?
I draw that lines on glasspane.
edit: that code is robust, so it is difficult to post it, and it is one part of thesis. principle is 2 color for example Color basicColor; Color similarColor;
than i have paint method and 2 hashmaps as attributes - some points are stored. i iterate over this map, remember that one point and similar to him, all other connect with graphics2D.drawLine(x1,y1,x2,y2) and than change color and paint last one line with another color. I am modifying stroke too, to make it more significant.
I hope it will be enough...
edit2: i have some Point similarPoint than some robust paint method and here is graphics modifying iterator iterate over list of points' lists.
Point similar = null;
Iterator<Point> secondIterator;
graphics.setColor(colorOfSimilar);
while (iterator.hasNext()) {
Point point = iterator.next();
if (point.equals(similarPoint)) {
similar = similarPoint;
} else {
secondIterator = secondMap.get(point).iterator();
while (secondIterator.hasNext()) {
Point secondPoint = secondIterator.next();
graphics2D.drawLine(point.getX(), point.getY(),
secondPoint.getX(), secondPoint.getY());
}
}
}
if (similar != null) {
secondIterator = secondMap.get(similar);
graphics2D.setColor(hooverColor);
graphics2D.setStroke(new BasicStroke(2.5f));
while (secondIterator.hasNext()) {
Point secondPoint = secondIterator.next();
graphics2D.drawLine(similar.getX(), similar.getY(),
secondPoint.getX(), secondPoint.getY());
}
graphics2D.setColor(colorOfSimilar);
graphics2D.setStroke(new BasicStroke(1.0f));
}
i wrote it in notepad so sorry about some mistakes (i think brackets etc.), but this is mechanism of modifying, around that is other methods for iterate and other, but it is not important. Problem with stroke doesn´t exist, because at first i did it without stroke.
Thanks for any idea.