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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:49:12+00:00 2026-05-11T00:49:12+00:00

This one’s a tough one – I have a JFrame that generates JTextFields. When

  • 0

This one’s a tough one – I have a JFrame that generates JTextFields. When I go from generating 2 JTextFields to 12 JTextfields (for example), I see some error where there is an extra differently-sized JTextField at the end. It seems to be a repaint error.

Main.java code:

import java.awt.*; import javax.swing.*;  public class Main {     public static Display display = new Display();      public static void main(String[] args) {         display.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         display.setVisible(true);     } } 

Display.java code:

import java.awt.*; import java.awt.event.*;  import javax.swing.*;  public class Display extends JFrame {     final int FRAME_WIDTH = 820;     final int FRAME_HEIGHT = 700;     final int X_OFFSET = 40;     final int Y_OFFSET = 40;      final int GRAPH_OFFSETX = 35;     final int GRAPH_OFFSETY = 60;     final int GRAPH_WIDTH = 500;     final int GRAPH_HEIGHT = 500;     final int GRAPH_INTERVAL = 20;      JButton submit;     JTextField top;     JTextField bottom;     JTextField numPoint;     JPanel bpanel;     JPanel points;      int maxPoints;      public Display() {         init();     }      public void init() {         setBackground(Color.WHITE);         setLocation(X_OFFSET, Y_OFFSET);         setSize(FRAME_WIDTH, FRAME_HEIGHT);         setTitle('Geometric Transformations');         getContentPane().setLayout(null);         setDefaultLookAndFeelDecorated(true);          top = new JTextField();    // parameter is size of input characters         top.setText('1 2 3');         top.setBounds(590, 150, 120, 25);          bottom = new JTextField();    // parameter is size of input characters         bottom.setText('5 6 7');         bottom.setBounds(590, 200, 120, 25);          numPoint = new JTextField();         numPoint.setText('Number of Points?');         numPoint.setBounds(550,200,200,25);         this.add(numPoint);          SubmitButton submit = new SubmitButton('Submit');         submit.setBounds(570, 250, 170, 25);          bpanel = new JPanel(new GridLayout(2,3));         bpanel.add(top);         bpanel.add(bottom);         bpanel.add(submit);          points = new JPanel(new GridLayout(2,2));         points.setBounds(540,250,265,60);         this.add(points);          bpanel.setBounds(550,100,200,70);         this.add(bpanel, BorderLayout.LINE_START);          Component[] a = points.getComponents();         System.out.println(a.length);         repaint();     }      public void paint(Graphics g) {         super.paint(g);         g.setColor(Color.WHITE);         g.fillRect(100, 100, 20, 30);         g.setColor(Color.BLACK);         genGraph(g, GRAPH_OFFSETX, GRAPH_OFFSETY, GRAPH_WIDTH, GRAPH_HEIGHT, GRAPH_INTERVAL);     }      public void genGraph (Graphics g, int x, int y, int width, int height, int interval) {         // draw background         int border = 5;         g.setColor(Color.BLACK);         width = width - (width % interval);         height = height - (height % interval);         for (int col=x; col <= x+width; col+=interval) {             g.drawLine(col, y, col, y+height);         }         for (int row=y; row <= y+height; row+=interval) {             g.drawLine(x, row, x+width, row);         }     }     class SubmitButton extends JButton implements ActionListener {          public SubmitButton(String title){             super(title);             addActionListener(this);             this.setVisible(true);         }         public void actionPerformed(ActionEvent e) {             maxPoints = Integer.parseInt(numPoint.getText()) * 2;              points.removeAll();              for (int i=0; i<maxPoints; i++) {                 JTextField textField = new JTextField();                 points.add(textField);             }             points.validate();        // necessary when adding components to a JPanel             // http://stackoverflow.com/questions/369823/java-gui-repaint-problem-solved             // What to Check:             // Things between commas are either spaces (which will be stripped later)             // or numbers!              // Pairs must match up!         }     } } 
  • 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. 2026-05-11T00:49:13+00:00Added an answer on May 11, 2026 at 12:49 am

    The new components are redrawn over the previous ones. I added points.repaint(); after points.validate(); and the problem was gone.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From here: Definition and Usage The tag provides no visual… May 11, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer For the people that eventually should land there: I've found… May 11, 2026 at 11:59 pm
  • Editorial Team
    Editorial Team added an answer You're going to need a little VSX for this (Visual… May 11, 2026 at 11:59 pm

Related Questions

I am currently running into a problem where an element is coming back from
This one will take some explaining. What I've done is create a specific custom
This one has me kind of stumped. I want to make the first word
This one has been bugging me for a while now. Is there a way
This one has me scratching my head. I'm running Subversion 1.3.1 (r19032) on Ubuntu.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.