I create this class to draw the line and extend it as a component.
class MyCanvas extends JComponent {
public void paint(Graphics g)
{
g.drawLine(30, 20, 80, 90);
}
}
...
frame.getContentPane().add(new MyCanvas());
After drawing, when adding text fields to frame, it disappears.
frstVectorField = new JTextField("");
frstVectorField.setBounds(600, 50, 160, 30);
frame.add(frstVectorField);
frame.setLayout(null);.