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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:43:14+00:00 2026-05-20T13:43:14+00:00

I made my own Component, named it ‘hi’ and put it in a JPanel

  • 0

I made my own Component, named it ‘hi’ and put it in a JPanel and then put that JPanel into a JFrame, but nothing shows up. I made a border around JPanel to see if JPanel is even on the JFrame and sure enough, it is there, but my Component ( which by the way draws arcs) isn’t on the JPanel.

    JFrame frame = new JFrame();
    JPanel panel = new JPanel();


    final int FRAME_WIDTH  = 400;
    final int FRAME_HEIGHT = 400;

    testComponent hi = new testComponent();
    panel.add(hi);
    frame.add(panel);
    panel.setBorder(BorderFactory.createLineBorder(Color.red));        



    frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

Thats what i have in the main, which is the basically the only thing in my test class. The testComponent() just has a paintComponent() that draws.

and the Component

public void paintComponent(Graphics g){
    Graphics2D g2 = (Graphics2D) g;
    g2.draw(new Arc2D.Double(100,100,100,100,0,30,Arc2D.PIE));
    g2.fill(new Arc2D.Double(100,100,100,100,30,330,Arc2D.PIE));
}

Like to note that, things like JButton, JTextField, etc. These work dandy in the JPanel

  • 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-20T13:43:14+00:00Added an answer on May 20, 2026 at 1:43 pm

    Try this code:

    import javax.swing.*;
    import java.awt.geom.*;
    import java.awt.*;
    public class PaintComponent extends JPanel
    {
        public PaintComponent()
        {
            setPreferredSize(new Dimension(400,400));
        }
        public void paintComponent(Graphics g)
        {
            Graphics2D g2d = (Graphics2D)g;
            g2d.draw(new Arc2D.Double(100,100,100,100,0,30,Arc2D.PIE));
            g2d.fill(new Arc2D.Double(100,100,100,100,30,330,Arc2D.PIE));
        }
    }
    

    ==============================================================================

    import javax.swing.*;
    import java.awt.*;
    public class MainClass
    {
        public static void main(String[] args)
        {
            JFrame frame = new JFrame();
            JPanel panel = new JPanel();
            final int FRAME_WIDTH  = 400;
            final int FRAME_HEIGHT = 400;
            PaintComponent hi = new PaintComponent();
            panel.add(hi);
            frame.add(panel);
            panel.setBorder(BorderFactory.createLineBorder(Color.red));
            frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.pack();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made my own overlay... worked great... but then I noticed that it was
I have made my own jQuery plugin, but it has problem that values I
I merged a branch to another branch and then made some of my own
I made a custom DatePicker that extends the android DatePicker UI component. I needed
just made my own bbcodes plugin for textarea but i wasn`t able to correct
I made my own framework and saw that my test application could load the
So i have made my own dict-based named-tuple class: class t(dict): def __getattr__(self, v):
So I made my own class in order to hold a 3D vertex. That
I made my own little tooltip, but there seems to be an issue when
I have made my own exception class which derives from runtime_error and is getting

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.