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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:28:50+00:00 2026-06-18T10:28:50+00:00

does anyone know how to refresh my JFrame so I can display my new

  • 0

does anyone know how to refresh my JFrame so I can display my new JButton ?

private void displayGrid()
{
   Case arrayGrid [][] = Grid.returnArray();

   for(int i = 0; i < Settings.returnYGrid(); i++)
    {
        for(int j = 0; j < Settings.returnXGrid(); j++)
        {
             Case caase = arrayGrid [i][j];
             panel.add(caase.getButton());
        }
}

Here is the method that I use when I create my JFrame. Then, I want to refresh my JFrame with the same method because some Case in my arrayGrid have changed and nothing is happening at all…

I tried to set revalidate(), repaint() and nothing either.

  • 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-18T10:28:51+00:00Added an answer on June 18, 2026 at 10:28 am

    Try adding a call to revalidate and repaint at the end of the method…

    private void displayGrid()
    {
       Case arrayGrid [][] = Grid.returnArray();
    
       for(int i = 0; i < Settings.returnYGrid(); i++)
        {
            for(int j = 0; j < Settings.returnXGrid(); j++)
            {
                 Case caase = arrayGrid [i][j];
                 panel.add(caase.getButton());
            }
        }
        panel.revalidate();
        panel.repaint();
    }
    

    Updated with working example

    public class TestFrame02 {
    
        public static void main(String[] args) {
            new TestFrame02();
        }
    
        public TestFrame02() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }
    
                    final JPanel panel = new JPanel(new GridLayout(0, 4));
                    JButton update = new JButton("Update");
                    update.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            for (int index = 0; index < 20; index++) {
                                panel.add(new JLabel(Integer.toString(index)));
                            }
                            panel.revalidate();
                            panel.repaint();
                        }
                    });
    
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(panel);
                    frame.add(update, BorderLayout.SOUTH);
                    frame.setSize(100, 100);
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
    
            });
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to disable the reload grid button (a.k.a. the refresh button)
Hi Does anyone know how to create a refresh button that when pressed it
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know what the refresh rate of the accelerometer in the wiimote is?
Does anyone know the best way to refresh custom.css in Thesis? I'm running into
Does anyone know how to reload/refresh a UICollectionView while the collection view is being
I'm trying to force PreferenceActivity to refresh. Does anyone know how to do this?
Does anyone know how I can reload an UpdatePanel on my parent C# page
does anyone know how to show the new list element form on button click,
Does anyone know how you refresh the names of the columns (the column headers)

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.