Results 1 to 2 of 2
  1. #1
    johnt is offline Super Moderator
    Join Date
    Apr 2007
    Posts
    30
    Rep Power
    0

    Default How to draw a thick line

    How can i draw thicker lines in my application?

  2. #2
    Hasan is offline Member
    Join Date
    May 2007
    Posts
    11
    Rep Power
    0

    Default

    You need to call setStroke method of Graphics2D.

    Check following example:

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

Similar Threads

  1. Draw an arrow
    By Albert in forum SWT / JFace
    Replies: 3
    Last Post: 02-01-2008, 08:11 AM
  2. help me draw... please...
    By kureikougaiji in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 12:22 PM
  3. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  4. Draw on JPanel, Help
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 06:56 AM
  5. how to draw in Java
    By Heather in forum AWT / Swing
    Replies: 2
    Last Post: 07-12-2007, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •