Difference Betwixt Repaint Together With Revalidate Method Inwards Coffee Swing

What is the departure betwixt revalidate() as well as repaint() inwards Java Swing is ane of the pop Swing Interview Questions particularly on Investment banks? Though both methods audio similar, at that spot is a subtle departure betwixt them. the revalidate() method teach LayoutManager to recalculate layout as well as ofttimes called ane time novel components are added or removed from Container. The revalidate() tin equally good trigger to telephone weep upwards to the repaint() method to repaint components which bring changed i.e. width, summit or whatsoever other visible property, which tin deport on layout. On the other mitt repaint() method puts a pigment asking inwards AWT thread, for repainting of a gene on which it has called.

Another follow-up of this questions is regarding thread-safety, What volition guide house if yous telephone weep upwards repaint() or revalidate() method from whatsoever thread, other than EDT? Many programmers confuse hither because they know Swing is unmarried threaded as well as properties of the gene should non last altered from a thread other than Event Dispatcher thread, simply interestingly repaint() as well as revalidate() method are thread-safe.

Since these method doesn't do whatsoever undertaking as well as they seat a asking for EDT, it makes feel them beingness thread-safe. By the way, at that spot is zip incorrect calling both revalidate() as well as repaint() later on adding novel components into the container, Since multiple impress asking tin last combined past times EDT thread.


Calling repaint() later on revalidate() ensures that your layout as well as concealment are upwards to date. So if yous are using whatsoever container, similar JFrame or JPanel as well as boot the bucket on adding as well as removing components, ever telephone weep upwards revalidate() as well as repaint() to refresh GUI.

 at that spot is a subtle departure betwixt them Difference betwixt repaint as well as revalidate method inwards Java Swing

That's all on the difference betwixt repaint as well as revalidate method of Swing. It's a worth preparing inquiry earlier appearing into whatsoever Java Swing Interview. This inquiry is non equally pop equally the departure betwixt invokeAndWait() as well as invokeLater(), simply however a practiced inquiry as well as equally an experienced Java developer, yous should know the departure betwixt these 2 methods.

Further Reading
Java Swing (GUI) Programming: From Beginner to Expert
answer)
  • Difference betwixt invokeAndWait() as well as invokeLater() inwards Java? (answer)
  • Top 10 AWT Swing Interview Questions alongside Answers (answer)
  • How to unopen a Swing Application inwards Java? (answer)
  • How to purpose List inwards Java Swing Application (tutorial)
  • What is blocking method inwards Java? (answer)
  • 12 Java Books for Experienced Developers (books)
  • Best books as well as Mock Exam for OCAJP 8 Certification (guide)

  • Thanks for reading this article, if yous similar this article as well as interview inquiry as well as therefore delight portion alongside your friends as well as colleagues. If yous bring whatsoever suggestion, feedback or inquiry as well as therefore delight driblet a comment. If yous desire to larn to a greater extent than nearly Swing framework then Java: The Complete Reference, Ninth Edition is worth reading. 

    Komentar

    Postingan populer dari blog ini

    Difference Betwixt Struts Validatorform Vs Validatoractionform - Interview Question

    How To Convert Inputstream To Byte Array Inwards Coffee - Two Examples

    Difference Betwixt Fileinputstream Together With Filereader Inwards Coffee | Inputstream Vs Reader