Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8842019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:51:41+00:00 2026-06-14T10:51:41+00:00

In Java, I need to draw a simple line with the paintComponent. Here is

  • 0

In Java, I need to draw a simple line with the paintComponent. Here is my attempt, but nothing was shown when I executed the program. Please show me the correct way of doing this.

import javax.swing.*;
import java.awt.*;

public class DrawLine extends JPanel {

    public Illusion(Color backColor){
        setBackground(backColor);
    }

    public void paintComponent(Graphics g){
        super.paintComponent(g);
        g.setColor(Color.black);
        g.drawLine(100, 100, 300, 100);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:51:43+00:00Added an answer on June 14, 2026 at 10:51 am

    Your painting a black line on a black background, so I’d say its working just fine. Try changing the color of the line

        g.setColor(Color.Red);
        g.drawLine(100, 100, 300, 100);
    

    Your also not taking into account the actual size of the panel, I’d do something more along the lines of

        g.drawLine(0, 0, getWidth(), getHeight());
    

    As a test

    You might like to have a read through

    • Creating a GUI With JFC/Swing
    • Graphics2D
    • Painting in AWT and Swing
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a java program to download a series of file from a web
I'm drawing images to pdf using Java framework iText. I need to draw lines
I am writing a java application using swing in which I need to draw
I have a program written in Java using JOGL with which you can draw
I need to create some simple graphics using java. Basically what I need to
I'm programming a java applet. In this applet I need to draw on an
I need to draw 3d projections and i am using opengl wrapper for JAVA.
I need to dynamically draw (star) topologies in a Java GUI application. By star
I need to draw a Pie Arc in Java with start angle 350 and
In java I need to make a Calendar object from a String in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.