Animating dashed-line with java.awt.BasicStroke
问题 Is there a way to produce animated dashed line using BasicStroke from java.awt? My desire is to have a running dashed-line in the same way that photoshop's rectangle marque tool has its line animated. 回答1: Use a dashed line, a Thread (or a Swing Timer ) & combine them with repaint() and some tweaking of where the dashes start and end - and there you have it. Example package test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java