title: How to draw vertical line in Swing
body: <p>I am able to draw a horizontal line but unable to draw a vertical line. Please help me. </p>
  
  <pre><code> import javax.swing.*;
      import java.awt.*;
      import java.awt.geom.*;
  
  class Success extends JFrame{
  
      public Success(){
          JPanel panel=new JPanel();
          getContentPane().add(panel);
          setSize(450,450);
  
          JButton button =new JButton("press");
          panel.add(button);
      }
  
      public void paint(Graphics g) {
          super.paint(g);  // fixes the immediate problem.
          Graphics2D g2 = (Graphics2D) g;
          Line2D lin = new Line2D.Float(20, 40, 850, 40);
          g2.draw(lin);
      }
  
      public static void main(String []args){
          Success s=new Success();
          s.setVisible(true);
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>