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?

Recommended Answers

All 2 Replies

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));
        }
}

oh wow, lol I'm a dumb.. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.