Which Swing component methods are thread safe?

前端 未结 5 858
情书的邮戳
情书的邮戳 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:29

    In Java 7, previously thread safe methods of the view components rooted in JTextComponent are no longer thread safe. A typical workaround using EventQueue.invokeLater() is shown here. The remaining model-related methods, listed here, remain thread safe.


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

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

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

提交回复
热议问题