Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8117632

Concurrency Bug in SimpleSwingBrowser.java Example

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7u25
    • Fix Version/s: 7u45
    • Component/s: docs

      Description

      This concerns the SimpleSwingBrowser application used to demonstrate embedding a JavaFX component in a Swing application:

          http://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm

      I believe this example does not follow the dictum that all all Swing objects should be created or modified only on the Event Dispatching Thread (EDT). The usual way to achieve this is:

          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  createAndShowGUI();
              }
          });

       
      However, the SimpleSwingBrowser.java example does it this way:

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new SimpleSwingBrowser());
          }
       

      SimpleSwingBrowser is a runnable, but the problem is that the evaluation of the "new SimpleSwingBrowser()" expression occurs on main's thread, and among other things, it involves the initialization of member fields which create Swing objects. For example:

          public class SimpleSwingBrowser implements Runnable {
              ...
              private JFrame frame = new JFrame();
              private JPanel panel = new JPanel(new BorderLayout());
              private JLabel lblStatus = new JLabel();

      While this will probably work anyway, it is not the best practice and should not be included in example code. This example is included in the following section of the JavaFX for Swing Developers manual: http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm
       

       

        Attachments

          Activity

            People

            • Assignee:
              ifedortsova Irina Fedortsova (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: