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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:34:25+00:00 2026-06-02T13:34:25+00:00

Having read many tutorials, articles and questions, I am still have confusions about updating

  • 0

Having read many tutorials, articles and questions, I am still have confusions about updating the GUI. Plus there are numerous related questions here on this website and still no luck – even though I think my problem is very simple.

Basically, I have a JFrame that has a JLayeredPane as its root container. And I have some layers of JPanels inside it.

The main issue is with updating a particular JPanel in this JLayeredPane. And for this particular Panel, I have implemented an update method that changes the contents inside it.

updatePanel(int para)
//doesn't remove this panel
//removes some existing labels and replaces it with new ones

Once I create the whole Frame, obviously just calling this method won’t show any change displayed the frame.

private void static main (String[] args){
    WindowFrame frame = new WindowFrame()//WindowFrame extends JFrame
    frame.updatePanel(2);
    .....
    .....
}

And that’s where I am stuck. I want to update the contents as the frame is displayed.

I saw these methods mentioned by people but due to nature of problems, I couldn’t fully grasped the concepts. Plus the documentation on these methods isn’t really helping – at least to me.

revalidate()
validate()
repaint()

How/when should these methods should be called? Or is this not the right way of what I should be doing, given these methods and the problem I am trying to solve?

Thank you for your time.

  • 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-02T13:34:26+00:00Added an answer on June 2, 2026 at 1:34 pm

    Basically you need two methods:

    revalidate()

    This method does the same as invalidate() but in AWT event dispatching thread (i will just call it Swing thread later on)). It updates container and all of its ancestors (parent containers in which this one is placed) layouting.

    Basically if you either move something inside this container or place/remove components inside of it you should call this method (or invalidate in case you are performing it in Swing thread, for example inside any Mouse/Action listener body or just inside).

    repaint()

    This method forces component, all its sub-components (if it has them) and parent container (basically if this component is NOT opaque) to update what they are “painting”.

    Usually you don’t need this method since all standard Swing components know when to repaint themselves and they do it on their own (that ofcourse depends on components UIs and some other things). This method might be useful in case you have your own specific components with some unique painting-way (for e.g. some custom selection over the components) and in some rare problematic cases with standard components.

    Also the way this method acts depends on the components placement (due to some Swing painting optimizations) – if you have some massive repaints rolling you’d better optimize them to repaint only those parts (rects) that you actually need to repaint. For example if you change the component bounds inside any container the best choice is either to repaint its old bounds rect and new bounds rect OR repaint rect that contains both of those bounds, but not the whole container to avoid repainting uninvolved in the action components.

    So, basically in your case after some changes with panels you should call revalidate on their container (or invalidate) followed by repaint (in case revalidate leaves some visual artefacts) again for the container.

    Guess i didn’t miss anything and i hope that now you know the basic meaning of those methods.

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

Sidebar

Related Questions

I have read a few tutorials and in a book about using Active Record,
Having read the documentation and many many articles I believe the following should work
I'm having problems with updating a child model via nested form. I've read many
I have read a number of questions on this site about this issue, I
Having read this article and many others out there on how to not store
Having read up on quite a few articles on Artificial Life (A subject I
Having read Fowler's Refactoring for a while, I still often catch myself thinking I
Having read around it appears this should be possible. I have the following content
Having read Apple's numerous documentation on icon guidelines: http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/IconsImages/IconsImages.html#//apple_ref/doc/uid/TP40006556-CH14-SW2 http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html#//apple_ref/doc/uid/TP40007072-CH6-SW1 http://developer.apple.com/library/ios/#qa/qa1686/_index.html I was wondering
I have read many posts regarding detection of popup blocker by javascript code but

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.