Which Swing component methods are thread safe?

前端 未结 5 857
情书的邮戳
情书的邮戳 2020-11-27 05:23

According to Swing tutorial:

Some Swing component methods are labelled \"thread safe\" in the API specification; these can be safely invoked from any

5条回答
  •  感情败类
    2020-11-27 05:42

    For a list of classes with the comment in the javadocs & src files "is thread safe" returns the following

    JEditorPane
    JTextArea
    AbstractDocument
    DefaultCaret
    DefaultStyledDocument
    JTextComponent    
    PlainDocument
    StyleContext    
    HTMLDocument
    UndoManager
    

    This is not saying that there are others documented or undocumented within the src that are thread safe.

    It strikes me as a rather strange question but I would treat most components as not being threadsafe and since Swing is a single threaded model and all updates need to happen on the event dispatcher thread this is pretty easy to do.

提交回复
热议问题