I cannot find any official documentation saying that it is safe to call Component.repaint
from another thread than the Event Dispatch Thread, the EDT.
Is this so? And where can I find some documentation/code?
I cannot find any official documentation saying that it is safe to call Component.repaint
from another thread than the Event Dispatch Thread, the EDT.
Is this so? And where can I find some documentation/code?
Here is a quote from an official page stating that:
The following JComponent methods are safe to call from any thread:
repaint()
,revalidate()
, andinvalidate()
. Therepaint()
andrevalidate()
methods queue requests for the event-dispatching thread to callpaint()
andvalidate()
, respectively.
EDIT 1 :
Since the previous link mentioned has been shifted. I am posting a new link, though it might take a bit more time to actually know the authenticity of this page, since it appears to be from Java
though it originated from some University
's server, as can be seen from the address bar.
It is thread-safe. The RepaintManager
ensures that such calls are placed in the Event Dispatch Thread.
Painting in AWT and Swing ("official" documentation)
The purpose of Swing's
RepaintManager
class is to maximize the efficiency of repaint processing on a Swing containment hierarchy, and also to implement Swing's 'revalidation' mechanism (the latter will be a subject for a separate article). It implements the repaint mechanism by intercepting all repaint requests on Swing components (so they are no longer processed by the AWT) and maintaining its own state on what needs to be updated (known as "dirty regions"). Finally, it usesinvokeLater()
to process the pending requests on the event dispatching thread, as described in the section on "Repaint Processing" (option B).For most programs, the RepaintManager can be viewed as part of Swing's internal system and can virtually be ignored. However, its API provides programs the option of gaining finer control over certain aspects of painting.
Component
API. –
Salve about the experiences on this forum
(+1 for both answerers) but, I think that not possible to answering your question correctly, part of methods Graphics(2D)
required call for repaint()
programatically, rest of them implementing this method (in API
) directly (sure some of them missing this method in API)
for part of Swing JComponents
is maybe better to dis-agree, this forum is full of questions about Concurency in Swing
, starting with Graphics(2D)
thought JTextComponents
, JTree
, and ends (same way is declared as thread safe) with setText()
,
about Concurency in Swing
are there notable numbers of questions
repaint()
. 2) While repaint()
itself is thread-safe, one typically calls it after updating a component, which isn't thread-safe. –
Salve © 2022 - 2024 — McMap. All rights reserved.
a)
everything works until repaint() isn't locked by Thread.sleep(int),b)
there were a few topics about isEventDispatchThread(), but those lins are lost on plundered Java.Netc)
agreed with API for AWT Components and for their nested classes in Swing – Pedigo