1

hey, so I know if I use the drawLine() method, then I could change the line stroke/thickness with setStroke, but how do I change the thickness of a Line2D?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by FALL3N
1

change the thickness of a Line2D

Hmm this shoud help:

import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

public class TestLine extends JFrame{
 private MyPanel panel;
 public TestLine() {
    setSize(200, 200);
    panel = new MyPanel();
    getContentPane().add( panel, "Center" );
    }

 public static void main( String [] args ){
    TestLine tl = new TestLine();
    tl.setVisible( true );
    }
}

class MyPanel extends JPanel {
    final static BasicStroke stroke = new BasicStroke(2.0f);
    final static BasicStroke wideStroke = new BasicStroke(8.0f);

    public MyPanel(){}

    public void paintComponent( Graphics g ){
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint
          (RenderingHints.KEY_ANTIALIASING, 
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setStroke( stroke );
        g2.draw(new Line2D.Double(10.0, 10.0, 100.0, 10.0));
        g2.setStroke( wideStroke );
        g2.draw(new Line2D.Double(10.0, 50.0, 100.0, 50.0));
        }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.