All I want to do is put a straight line under my 3 labels which I have loaded into a JFrame.

After my JFrame has loaded I use the method repaint() which is supposed to call:

public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;


Which does not draw my line. The method repaint() does not even allow me to go to the method paintComponent(Graphics comp). What am I doing wrong

Any help would be appreciated

Recommended Answers

All 4 Replies

This is how I do my lines but I just started java a month ago and it is the only way I have been introduced to.

public void paint(Graphics g) {
g.drawLine(25, 0, 25, 50);

public void draw (Graphics g)

function is not supported for the JFrame. Indeed JFrame does not have any painting capability.

You can either use the draw function for Applets or you can use a Swing component with draw capability like JPanel.

Below code should work :

import javax.swing.*;
import java.awt.*;
public class cizim extends JPanel{
  public void paintComponent(Graphics g){
  public static void main(String args[]){
    JFrame jf = new JFrame();
    jf.add(new cizim());


Don't post in tool old dead threads if you have any new thing to share then create a new thread

>> Don't post in tool old dead threads if you have any new thing to share then create a new thread

There's nothing in the rules that forbids people to post in an old thread as long as the reply is on-topic and not just another question (thread-hijacking).
The post made by "shedai" is on-topic and might help people who have the same problem and find this thread on google.

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.