Swing and JavaFX thread merge

Artem Ananiev artem.ananiev at oracle.com
Tue Aug 13 07:31:35 PDT 2013


Jeff, Werner,

thank you very much for detailed evaluation. The issues you observe may 
be related to recent changes in AWT/Swing in 7u25. If my guess is 
correct, they should be fixed in the latest 7u40 builds. I know it's not 
released yet, but early access builds are available at java.net. Could 
you run your apps with 7u40 and check if the problems are gone, please?

Thanks,

Artem

On 8/12/2013 4:51 PM, Werner Lehmann wrote:
> Hi,
>
> coincidentally we were experiencing the exact same problem with the
> combination 7u25, OSX, Webstart. Also, we arrived at pretty much the
> same workaround.
>
> Investigation showed that multiple Swing eventqueues were created in the
> above configuration. This would cause threading issues (NPE), paint
> issues (flicker etc), drag-drop issues.
>
> See below for a testcase: JFrame with a JButton and an fx button. When
> clicked, the former prints its current thread, while the later switches
> to EDT first (invokeLater) and then also prints the thread. On Windows,
> this turns out to be the same thread as expected. On WebStart 7u25 OSX
> we are getting different AWT-EventQueue-X threads.
>
> Werner
>
>> public class TestSwingEDT extends JFrame{
>>
>>   public static void main(final String[] args){
>>     SwingUtilities.invokeLater(new Runnable() {
>>       @Override
>>       public void run() {
>>         new TestSwingEDT().runTest(args);
>>       }
>>     });
>>   }
>>
>>   private void runTest(String[] args){
>>
>>     System.out.println("runTest in " + Thread.currentThread().getName());
>>
>>     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
>>     this.setSize(300, 200);
>>
>>     final JFXPanel jfxPanel = new JFXPanel();
>>     Platform.runLater(new Runnable(){
>>       @Override
>>       public void run() {
>>         Button btn = new Button("click me");
>>         btn.onActionProperty().set(new EventHandler<ActionEvent>() {
>>           @Override public void handle(ActionEvent ae) {
>>             System.out.println("jfx button click in " +
>> Thread.currentThread().getName());
>>             SwingUtilities.invokeLater(new Runnable() {
>>               @Override public void run() {
>>                 System.out.println("invokeLater from jfx button click
>> in " + Thread.currentThread().getName());
>>               }
>>             });
>>           }
>>         });
>>         HBox hbox = new HBox();
>>         hbox.getChildren().add(btn);
>>         jfxPanel.setScene(new Scene(hbox));
>>       }
>>     });
>>
>>     JButton jbutton = new JButton("click me");
>>     jbutton.addActionListener(new ActionListener() {
>>       @Override public void actionPerformed(java.awt.event.ActionEvent
>> e) {
>>         System.out.println("jbutton click in " +
>> Thread.currentThread().getName());
>>       }
>>     });
>>
>>     JPanel rootPanel = new JPanel();
>>     rootPanel.add(jbutton);
>>
>>     this.getContentPane().add(jfxPanel, BorderLayout.NORTH);
>>     this.getContentPane().add(rootPanel, BorderLayout.CENTER);
>>
>>     this.setVisible(true);
>>
>>     Platform.runLater(new Runnable(){
>>       @Override
>>       public void run() {
>>         SwingUtilities.invokeLater(new Runnable() {
>>           @Override
>>           public void run() {
>>             System.out.println("invokeLater in Platform.runLater in "
>> + Thread.currentThread().getName());
>>           }
>>         });
>>       }
>>     });
>>
>>   }
>> }


More information about the openjfx-dev mailing list