Thanks Kevin, I did it like that :)

Matthias


> Am 19.05.2015 um 16:59 schrieb Kevin Rushforth <kevin.rushfo...@oracle.com>:
> 
> Actually, I was saying that you should call Platform.setImplicitExit(false). 
> This is good practice for Swing interop applications, and is absolutely 
> needed in your case. l Note that this is attribute state so you only need to 
> do it once at the beginning of your application.
> 
> My other point is that you should not use the internal PlatformImpl class at 
> all. It is not supported now, and will stop working in JDK 9. What you should 
> do instead is this:
> 
>     Platform.setImplicitExit(false);
>     new JFXPanel();
>     Platform.runLater(() -> {
>         // your code goes here....
>     });
> 
> You don't actually need to do anything with the JFXPanel unless you want to 
> use it to display a JavaFX scene in a Swing component.
> 
> -- Kevin
> 
> 
> Matthias Hänel wrote:
>> Hey Tom and Kevin,
>> 
>> 
>> thanks for you answers.
>> 
>> 
>> I see setImplicitExit should be avoided but I don't get it working without.
>> 
>> I have now a running version with follwing code:
>> 
>> 
>> public void show()
>> {
>>     Platform.setImplicitExit(false);
>>     if( invisibleJFXPanel==null )
>>     {
>>         PlatformImpl.startup(new Runnable()
>>         {
>>             @Override
>>             public void run()
>>             {
>>                 invisibleJFXPanel = new JFXPanel();
>>                 invisibleJFXPanel.setSize(100,100);
>>                 invisibleJFXPanel.setVisible(true); // this should be 
>> invisible in the future
>>             }
>>         });
>>     }
>>     
>>     PlatformImpl.runLater(new Runnable()
>>     {
>>         @Override
>>         public void run()
>>         {
>>             myStage = new MyStage();
>>             myStage();
>>         }
>>     });
>> }
>> 
>> public void hide()
>> {
>>     Platform.setImplicitExit(false);
>>     if (myStage != null)
>>     {
>>         Platform.runLater(new Runnable()
>>         {
>>             @Override
>>             public void run()
>>             {
>>                 myStage.hide();
>>             }
>>         });
>>     }
>> }
>> 
>> 
>> When I understand Kevin correctly, this code should work without any call to 
>> Platform.setImplicitExit(false);
>> Unfortunately, it does not.
>> 
>> 
>> regards
>> Matthias
>> 
>> 
>> 
>>   
>> 
>>> Am 18.05.2015 um 17:24 schrieb Kevin Rushforth <kevin.rushfo...@oracle.com>
>>> :
>>> 
>>> 
>>> You should call Platform.setImplicitExit(false) to disable the default 
>>> behavior where the FX toolkit exits when the last Stage is closed.
>>> 
>>> One more suggestion:
>>> 
>>>     
>>> 
>>>> PlatformImpl.startup(new Runnable()
>>>>       
>>>> 
>>> This is not public API and should be avoided. If you are running a Swing 
>>> application and want to startup the FX toolkit, you should create a new 
>>> instance of JFXPanel (even if you don't use it).
>>> 
>>> 
>>> -- Kevin
>>> 
>>> 
>>> 
>>> 
>>> Matthias Hänel wrote:
>>>     
>>> 
>>>> Hello there,
>>>> 
>>>> 
>>>> I have a stage that is been called from a Java Swing application. This is 
>>>> not a real problem
>>>> since I can run follwing code:
>>>> 
>>>> PlatformImpl.startup(new Runnable()
>>>> {
>>>>    @Override
>>>>    public void run()
>>>>    {
>>>>        myStage = new myStage();
>>>>        myStage.show();
>>>>    }
>>>> });
>>>> 
>>>> 
>>>> That works so far. 
>>>> No I would like to close this stage from the swing application. I can call:
>>>> 
>>>> Platform.runLater(new Runnable()
>>>> {
>>>>    @Override
>>>>    public void run()
>>>>    {
>>>>        myStage.hide();
>>>>    }
>>>> });
>>>> 
>>>> 
>>>> This also works. 
>>>> Since I have a toggle-Button to hide and show the stage from the swing 
>>>> application, I would like
>>>> to re-show the stage and I would like to know when the stage is showing or 
>>>> not. This seems to be nearly impossible by now.
>>>> 
>>>> What did I try?
>>>> 
>>>> 1. I tried to shutdown the javafx entire with 
>>>> com.sun.javafx.tk.Toolkit.getToolkit().exit(); in the hide process. So I 
>>>> expected to use PlatformImpl.startup again. Unfortunately, it did not work.
>>>> 
>>>> 2. I tried to leave javafx untouched. The second time I only call 
>>>> PlatformImpl.runLater to create a new scene.
>>>> 
>>>> 3. I tried to run it from the swing thread without Platform.run... ... 
>>>> this failed obviuosly. (I just had no further ideas ;)) 
>>>> 
>>>> Does anyone tried this before? Any advise will be helpful :)
>>>> 
>>>> 
>>>> 
>>>> Thanks in advance
>>>> Matthias
>>>> 
>>>> 
>>>> 
>>>>  
>>>>       
>>>> 
>> 
>>   
>> 

Reply via email to