1. How do I draw a dotted line from the paint method on a JComponent? stackoverflow.comI have to draw a dotted or dashed line In a JComponent. How do I do that? |
2. Draw dotted Rect coderanch.comNot Graphics, but Graphics2D does... As long as you're using any version of the JDK newer than 1.2 you can just cast the Graphics parameter of the paint() method to a Graphics2D object. import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Stroke; import java.awt.geom.Rectangle2D; import javax.swing.JComponent; import javax.swing.JFrame; public class DottedRectangle extends JComponent { public void paintComponent( Graphics og ) { Graphics2D ... |