Difference Betwixt Repaint In Addition To Revalidate Method Inward Coffee Swing

What is the divergence betwixt revalidate() together with repaint() inward Java Swing is 1 of the pop Swing Interview Questions particularly on Investment banks? Though both methods audio similar, at that topographic point is a subtle divergence betwixt them. the revalidate() method learn LayoutManager to recalculate layout together with oft called 1 time novel components are added or removed from Container. The revalidate() tin likewise trigger to telephone band to the repaint() method to repaint components which bring changed i.e. width, summit or whatever other visible property, which tin comport on layout. On the other manus repaint() method puts a pigment asking inward AWT thread, for repainting of a ingredient on which it has called.

Another follow-up of this questions is regarding thread-safety, What volition move on if yous telephone band repaint() or revalidate() method from whatever thread, other than EDT? Many programmers confuse hither because they know Swing is unmarried threaded together with properties of the ingredient should non move altered from a thread other than Event Dispatcher thread, merely interestingly repaint() together with revalidate() method are thread-safe.

Since these method doesn't do whatever project together with they pose a asking for EDT, it makes feel them beingness thread-safe. By the way, at that topographic point is aught incorrect calling both revalidate() together with repaint() afterwards adding novel components into the container, Since multiple impress asking tin move combined past times EDT thread.


Calling repaint() afterwards revalidate() ensures that your layout together with shroud are upwards to date. So if yous are using whatever container, similar JFrame or JPanel together with move along adding together with removing components, ever telephone band revalidate() together with repaint() to refresh GUI.

 at that topographic point is a subtle divergence betwixt them Difference betwixt repaint together with revalidate method inward Java Swing

That's all on the difference betwixt repaint together with revalidate method of Swing. It's a worth preparing query earlier appearing into whatever Java Swing Interview. This query is non equally pop equally the divergence betwixt invokeAndWait() together with invokeLater(), merely however a practiced query together with equally an experienced Java developer, yous should know the divergence betwixt these ii methods.

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

  • Thanks for reading this article, if yous similar this article together with interview query thus delight part alongside your friends together with colleagues. If yous bring whatever suggestion, feedback or query thus delight drib a comment. If yous desire to larn to a greater extent than most Swing framework then Java: The Complete Reference, Ninth Edition is worth reading. 

    0 Response to "Difference Betwixt Repaint In Addition To Revalidate Method Inward Coffee Swing"

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel