I am developing a navigation system in Java. The map should be drawn in the middle, with indicators on the left and right.
How do I make the map slowly fade out on both sides?
As shown above, the roads are drawn across the entire window via Graphics2D. How can I make a gradient with left and right transparent and center color x?
for(Street street : streets){
g2d.setColor(Color.BLACK);
if(street.distanceToCurrentPosition() * factor < width * 2){
Integer last_x = null;
Integer last_y = null;
street.setupGraphicSettings(g2d);
if(street.getType() != ""){
for(WayPoint wayPoint : street.getWayPoints()){
int waypoint_x = (int) (wayPoint.getDistanceLongitudeTo(current_position) * factor) + middle_x;
int waypoint_y = - (int) (wayPoint.getDistanceLatitudeTo(current_position) * (double) factor) + middle_y;
if(last_x != null || last_y != null){;
g2d.drawLine(waypoint_x, waypoint_y, last_x, last_y);
}
last_x = waypoint_x;
last_y = waypoint_y;
}
}
}else return;
A working code solution

The "basic" idea is to use a combination of
LinearGradientPaintandAlphaCompositeto apply an alpha based "mask" to the core map image - now, this assumes you have an image based map.Start by taking a look at:
Basically, we create a alpha based "mask":
Note, we're not really interested in the color, just there alpha values.
Next, we use a
AlphaComposite.DST_INto "mask" the source image, this done via a utility method...Runnable example
NB: The component's background is set to red to demonstrate the alpha masking