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 525513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:40:46+00:00 2026-05-13T08:40:46+00:00

I created a new JApplet form in NetBeans: public class UI extends javax.swing.JApplet {

  • 0

I created a new JApplet form in NetBeans:

public class UI extends javax.swing.JApplet {
    //generated code...
}

And a JPanel in design mode named panou:

// Variables declaration - do not modify                     
private javax.swing.JPanel panou;

How do I get to draw a line on panou? I’ve been searching for this for 5 hours now so a code snippet and where to place it would be great. Using Graphics2D preferably.

  • 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-05-13T08:40:47+00:00Added an answer on May 13, 2026 at 8:40 am
    1. Go to design mode
    2. Right Click on the panel "panou"
    3. Click "Costumize code"
    4. In the dialog select in the first combobox "costum creation"
    5. add after = new javax.swing.JPanel() this, so you see this:

     

    panou = new javax.swing.JPanel(){
        @Override
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g); // Do the original draw
            g.drawLine(10, 10, 60, 60); // Write here your coordinates
        }
    };
    

    Make sure you import java.awt.Graphics.

    The line that you will see is always one pixel thick. You can make it more "line" by doing the following:

    Create this method:

    public static final void setAntiAliasing(Graphics g, boolean yesno)
    {
        Object obj = yesno ? RenderingHints.VALUE_ANTIALIAS_ON
                     : RenderingHints.VALUE_ANTIALIAS_OFF;
    
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, obj);
    }
    

    And add after super.paintComponent(g); (in your costum creation) this:

    setAntiAlias(g, true);
    

    Edit:

    What you are doing wrong is: you paint the line once (by creating the frame).
    When you paint the line the frame is also invisible. The first draw is happening when the frame becomes visible. The frame will be Repainted, so everything from the previous paint will disappear.

    Always you resize the frame, everything will be repainted. So you have to make sure each time the panel is painted, the line also is painted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I ran this program: import javax.swing.*; import java.awt.*; public class DrawApplet extends JApplet{
I created a new project with the following code segment: char* strange = (Strange??);
I have created a JApplet using the JUNG library in Netbeans that compiles and
I have created new class to read the data from xml file, which looks
I have created new class which handles button. It does nothing (just for test,
I have a ghashtable object as member of my class. I have created new
Hi i have created new iFrame APP. this is code part: <fb:visible-to-connection>Welcome, fans!<fb:else>Become fan</fb:else></fb:visible-to-connection>
Sorry for my bad English. I wrote implementation for AbstractRoutingDataSource: public class DatabaseRoutingDataSource extends
I've created new Windows Forms Application (C#) with one simple form containing ListView. Then
I've created new db via phpMyAdmin and while editing db privilages clicked delete localhost

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.