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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:11:45+00:00 2026-06-12T16:11:45+00:00

I have a JButton, in a JPanel, in a JApplet, that when clicked, does

  • 0

I have a JButton, in a JPanel, in a JApplet, that when clicked, does some stuff, changes the contents of the JPanel, then should repaint. However, it doesn’t seem like it’s repainting anything more than the button its self and the JPanel is repainting it’s self too. However, I think I need to have the JApplet repaint itsself. Essentially, Ill click one of the buttons, the buttons will change, but the JLabels won’t show up. Once I rezise the applet, or in the browser make it so small that the sides of the browser touch the applet, it all resets and looks great!
One of the buttons code is as follows:

reset.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                //resets the vars
            questions = 0;
            wrong = 0;
            correct = 0;
            //clears the JPanel
            overallJP.removeAll();
            //adds new question, and buttons
            rand = generator.nextInt(10);
            JLabel tmp = new JLabel("Answer the Question: "+"\n"+qArr.get(rand).getQuestion());
            overallJP.setSize(new Dimension(500,700));
            overallJP.add(tmp);
            overallJP.add(buttonArea);
            overallJP.repaint();
            setVisible(true);
            repaint();
            }
        });

And the other buttons look similar. I think the problem is on the repaint() at the bottom. Is there a way to call the JApplet’s repaint from inside this anonymous function? The reset button is declared in the init() of the applet. If you have more questions or need more code, just ask!

  • 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-12T16:11:47+00:00Added an answer on June 12, 2026 at 4:11 pm

    Since you’re removing components from the panel, you may need to revalidate it. Try adding: validate();

    EDIT:

    Container.validate() triggers container’s re-layout. It should be invoked when container is modified – components added, removed, etc after the container has been displayed.

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

Sidebar

Related Questions

I have a JPanel that I want to add some components. in particular JButton
I have a class that extends javax.swing.JPanel , it contains a single JButton. I've
I have a program which creates JButtons which are then added to a JPanel
I have a JButton MAIN_BUTTON in a window. When it is clicked it starts
I have a jTable and a jButton. When clicked, the button's actionPerformed method calls
I have a JFrame with some a JTextField and a JButton. I want it
I have a class that extends JPanel with several buttons on it. I would
I have a JLabel, a JButton, and a JTextField all arranged horizontally in that
I have a cell editor that is composed of several components on a JPanel.
I have a subclass of JFrame(it contains JButton, Title and Jpanel) and i added

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.