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

  • Home
  • SEARCH
  • 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 8846851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:57+00:00 2026-06-14T12:05:57+00:00

I am trying to allow my program to add more rows of content that

  • 0

I am trying to allow my program to add more rows of content that will eventually allow them to input point values (x & y). However, I cannot seem to get my JPanel to actually add anything when the add button is pressed.

Here is the class (JPanel extension) that I am trying to add to my overall JPanel:

class Coordinates extends JPanel
{
  public String x;
  public String y;
  public int id;

  public Coordinates(int spot)
  {
    super();
    x = "0";
    y = "0";
    id = spot;
    setLayout(null);
    setSize(440,30);
    setLocation(10,5);
    JLabel num = new JLabel("Point #" + (id + 1) + ":");
    num.setLocation(0,0);
    num.setSize(40,20);
    add(num);
  }
}

And here is the AbstractAction extension for the add button that should add it when pressed:

class AddACT extends AbstractAction
{
  public void actionPerformed(ActionEvent e)
  {
    pointList.add(new Point());
    gui.add(new Coordinates(1));
  }
}

And, if anyones up for a massive block of code, here’s the entire window’s code:

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

public class PointWindow
{
  private ArrayList<Point> pointList = new ArrayList<Point>();

  public PointWindow()
  {
    initialize();
  }

  public void initialize()
  {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Set New Points");
    frame.setContentPane(createGUI());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(440,600);
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);
  }

  public JPanel createGUI()
  {
    final JPanel gui = new JPanel();
    gui.setLayout(null);

    Font boldTitle = new Font("Arial", Font.BOLD, 30);

    class Line extends JPanel
    {
      protected void paintComponent(Graphics g)
      {
        super.paintComponent(g);
        g.drawLine(0,0,430,0);
      }
    }

    class Coordinates extends JPanel
    {
      public String x;
      public String y;
      public int id;

      public Coordinates(int spot)
      {
        super();
        x = "0";
        y = "0";
        id = spot;
        setLayout(null);
        setSize(440,30);
        setLocation(10,5);
        JLabel num = new JLabel("Point #" + (id + 1) + ":");
        num.setLocation(0,0);
        num.setSize(40,20);
        add(num);
      }
    }

    final JButton add = new JButton("Add");
    final JButton remove = new JButton("Remove");
    final JButton makeGraph = new JButton("Generate Graph!");

    final JLabel numPointsL = new JLabel("0");

    class AddACT extends AbstractAction
    {
      public void actionPerformed(ActionEvent e)
      {
        pointList.add(new Point());
        gui.add(new Coordinates(1));
      }
    }

    class RemoveACT extends AbstractAction
    {
      public void actionPerformed(ActionEvent e)
      {

      }
    }

    class MakeGraphACT extends AbstractAction
    {
      public void actionPerformed(ActionEvent e)
      {

      }
    }

    JPanel line1 = new JPanel();
    line1.setLayout(null);
    line1.setLocation(5,5);
    line1.setSize(440,35);
    gui.add(line1);

    JLabel text1 = new JLabel("Point Manager");
    text1.setFont(boldTitle);
    text1.setLocation(0,0);
    text1.setSize(300,35);
    line1.add(text1);

    add.setLocation(220,0);
    add.setSize(100,33);
    add.addActionListener(new AddACT());
    line1.add(add);

    remove.setLocation(330,0);
    remove.setSize(100,33);
    add.addActionListener(new RemoveACT());
    line1.add(remove);

    JPanel line2 = new JPanel();
    line2.setLayout(null);
    line2.setLocation(5,45);
    line2.setSize(440,30);
    gui.add(line2);

    JLabel text2 = new JLabel("Current number of points:");
    text2.setLocation(2,1);
    text2.setSize(165,20);
    line2.add(text2);

    numPointsL.setLocation(172,1);
    numPointsL.setSize(40,20);
    line2.add(numPointsL);

    makeGraph.setLocation(222,0);
    makeGraph.setSize(206,22);
    makeGraph.addActionListener(new MakeGraphACT());
    line2.add(makeGraph);

    Line l1 = new Line();
    l1.setLocation(5,29);
    l1.setSize(420,1);
    line2.add(l1);

    return gui;
  }
}
  • 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-14T12:05:58+00:00Added an answer on June 14, 2026 at 12:05 pm

    They are begin added, but it’s begin added behind the other components.

    Instead of using setLocation(10,5) try setLocation(5, 75), which will place it underneath the line.

    Also, call gui.repaint() after the add call to request that the ui be repainted

    More importantly, use layout managers.

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

Sidebar

Related Questions

I'm trying to add functionality in my program that will allow the user to
I'm trying to add a menu to my Javascript program that will allow a
I'm working on a program that will allow me to multiply/divide/add/subtract binary numbers together.
I am trying to create a simple program that will allow the user to
i'm trying to implement some functions that allow me to add Books to a
i've been trying to modify the program so that it could accept more than
OK, so I am trying to make a program using Visual Basic that will
I'm trying to make a program that will draw lines over a picturebox using
I am trying to create a SQL statement that will allow me to remove
I'm trying to create an app in Visual Basic that will allow a user

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.