哪种Swing组件方法是线程安全的? [英] Which Swing component methods are thread safe?

查看:174
本文介绍了哪种Swing组件方法是线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Swing教程


一些Swing组件方法在API规范中标记为线程安全;这些可以从任何线程安全地调用。必须从事件派发线程调用所有其他Swing组件方法。忽略此规则的程序可能在大多数情况下正常运行,但会遇到难以重现的不可预测的错误。

Some Swing component methods are labelled "thread safe" in the API specification; these can be safely invoked from any thread. All other Swing component methods must be invoked from the event dispatch thread. Programs that ignore this rule may function correctly most of the time, but are subject to unpredictable errors that are difficult to reproduce.

但是这些标记为线程安全的Swing组件方法是什么?实际上有吗?

But what are these Swing component methods that are labelled "thread safe"? Are there actually any?

是否有完整列表的线程安全摆动方法? (线程安全的Swing方法似乎很少见,所以这样的列表不能太长......)

Is there a complete list of thread-safe swing methods? (The thread-safe Swing methods seems to be quite rare, so such list can't be too long...)

推荐答案

谷歌教我至少那些是线程安全的。以下是链接再次破坏的情况概述:

Google taught me that at least those are threadsafe. Here's an overview for the case that the link get broken again:


  • JTextPane


    • replaceSelection()

    • insertComponent()

    • insertIcon()

    • setLogicalStyle()

    • setCharacterAttributes()

    • setParagraphAttributes()

    • JTextPane
      • replaceSelection()
      • insertComponent()
      • insertIcon()
      • setLogicalStyle()
      • setCharacterAttributes()
      • setParagraphAttributes()

      • JTextArea


        • insert()

        • append()

        • replaceRange()

        • JTextArea
          • insert()
          • append()
          • replaceRange()

          • JTextComponent


            • replaceSelection()

            • setText()

            • print()

            • getPrintable()

            • JTextComponent
              • replaceSelection()
              • setText()
              • print()
              • getPrintable()

              • UndoManager


                • 所有方法。


                • DefaultStyledDocument


                  • insert()

                  • setLogicalStyle()

                  • setCharacterAttributes()

                  • setParagraphAttributes()

                  • DefaultStyledDocument
                    • insert()
                    • setLogicalStyle()
                    • setCharacterAttributes()
                    • setParagraphAttributes()

                    • StyleContext


                      • addAttribute()

                      • addAttributes()

                      • removeAttribute()

                      • removeAttributes()

                      • reclaim()

                      • StyleContext
                        • addAttribute()
                        • addAttributes()
                        • removeAttribute()
                        • removeAttributes()
                        • reclaim()

                        • AbstractDocument


                          • render()

                          • remove()

                          • insertString()

                          • createPosition()

                          • AbstractDocument
                            • render()
                            • remove()
                            • insertString()
                            • createPosition()

                            • PlainDocument


                              • insertString()

                              • PlainDocument
                                • insertString()

                                • HTMLDocument


                                  • setParagraphAttributes()

                                  • HTMLDocument
                                    • setParagraphAttributes()

                                    这篇关于哪种Swing组件方法是线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆