How can i draw thicker lines in my application?
Printable View
How can i draw thicker lines in my application?
You need to call setStroke method of Graphics2D.
Check following example:
Code:import java.awt.*;
import javax.swing.*;
public class StrokeExample extends JPanel implements Runnable {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
g.drawLine(0,0,w,h); //default
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3));
g2.drawLine(0,h,w,0); //thick
}
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new StrokeExample());
f.setSize(500,400);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new StrokeExample());
}
}