Difference Betwixt Repaint In Addition To Revalidate Method Inwards Coffee Swing

What is the deviation betwixt revalidate() together with repaint() inwards Java Swing is 1 of the pop Swing Interview Questions peculiarly on Investment banks? Though both methods audio similar, at that spot is a subtle deviation betwixt them. the revalidate() method learn LayoutManager to recalculate layout together with frequently called in 1 lawsuit novel components are added or removed from Container. The revalidate() tin besides trigger to telephone band to the repaint() method to repaint components which accept changed i.e. width, overstep or whatever other visible property, which tin behave on layout. On the other manus repaint() method puts a pigment asking inwards AWT thread, for repainting of a cistron on which it has called.

Another follow-up of this questions is regarding thread-safety, What volition travel 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 cistron should non last altered from a thread other than Event Dispatcher thread, only interestingly repaint() together with revalidate() method are thread-safe.

Since these method doesn't practice whatever labor together with they lay a asking for EDT, it makes feel them existence thread-safe. By the way, at that spot is zip incorrect calling both revalidate() together with repaint() later adding novel components into the container, Since multiple impress asking tin last combined past times EDT thread.


Calling repaint() later revalidate() ensures that your layout together with enshroud are upward to date. So if yous are using whatever container, similar JFrame or JPanel together with give-up the ghost on adding together with removing components, ever telephone band revalidate() together with repaint() to refresh GUI.

 at that spot is a subtle deviation betwixt them Difference betwixt repaint together with revalidate method inwards Java Swing

That's all on the difference betwixt repaint together with revalidate method of Swing. It's a worth preparing inquiry earlier appearing into whatever Java Swing Interview. This inquiry is non every bit pop every bit the deviation betwixt invokeAndWait() together with invokeLater(), only withal a proficient inquiry together with every bit an experienced Java developer, yous should know the deviation betwixt these 2 methods.

Further Reading
Java Swing (GUI) Programming: From Beginner to Expert
answer)
  • Difference betwixt invokeAndWait() together with 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 together with Mock Exam for OCAJP 8 Certification (guide)

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

    Sumber https://javarevisited.blogspot.com/

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

    Post a Comment

    Iklan Atas Artikel

    Iklan Tengah Artikel 1

    Iklan Tengah Artikel 2

    Iklan Bawah Artikel