Discussion:
"Toolkit already initialized" error with OpenJDK 11
marcel Austenfeld
2018-09-26 11:20:28 UTC
Permalink
marcel Austenfeld
2018-09-26 11:22:49 UTC
Permalink
First of all congratulation to the new release and thank you for the hard work on JavaFX.
 
 
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
 
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
 
This works fine in Java 8 which my current release depends on.
 
However in Java 11 after the second panel is initialized at startup I get the following error:
 
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
 
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
 
 
Thanks in advance for any help.
Kevin Rushforth
2018-09-26 12:09:02 UTC
Permalink
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
one time) before creating your first FXCanvas:

    Platform.setImplicitExit(false);

-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
marcel Austenfeld
2018-10-04 13:03:02 UTC
Permalink
Hello Kevin,
 
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
 
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
 
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
 
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
 
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
 
Maybee this has something to do with the new module system of Java >=9?
 
 
 

Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Von: "Kevin Rushforth" <***@oracle.com>
An: "marcel Austenfeld" <***@web.de>, openjfx-***@openjdk.java.net
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
one time) before creating your first FXCanvas:

    Platform.setImplicitExit(false);

-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
 
Kevin Rushforth
2018-10-04 14:13:51 UTC
Permalink
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.

So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.

-- Kevin
Post by marcel Austenfeld
Hello Kevin,
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
Tom Schindl
2018-10-04 14:35:17 UTC
Permalink
Hi,

FXCanvas should not be loaded multiple times. This sounds like a severe
bug in e(fx)clipse OSGi-Adapterhooks.

Tom
Post by Kevin Rushforth
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.
So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.
-- Kevin
Post by marcel Austenfeld
Hello Kevin,
"java.lang.IllegalStateException: Toolkit already initialized".
  However I found out that this error only occurs if I call SWT
FXCanvas classes located in different Eclipse plugins.
  I can create multiple JavaFX canvas if they are located in one
Eclipse plugin.
  Vice versa if I try to to open the JavaFX SceneBuilder canvas which
is located in a seperate Eclipse plugin this error occurs again.
  So I wonder that beginning with Java 9 the JavaFX toolkit doesn't
recognize an already started toolkit in another Eclipse plugin (which
was definitely the case with Java 8!).
  Maybee this has something to do with the new module system of Java >=9?
     
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
     Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the
hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich
Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a
SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
However in Java 11 after the second panel is initialized at startup I
"Caused by: java.lang.IllegalStateException: Toolkit already
initialized"
Is there a new option available to avoid a new initialization of the
toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
 
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
marcel Austenfeld
2018-10-05 06:38:30 UTC
Permalink
Hello Kevin,

thanks for the analysis.

I think this is the cause since each Eclipse plugins have their own classloader and I have several plugins with JavaFX classes. I will write a bug report on:

https://bugs.java.com/




 
 

Gesendet: Donnerstag, 04. Oktober 2018 um 16:13 Uhr
Von: "Kevin Rushforth" <***@oracle.com>
An: "marcel Austenfeld" <***@web.de>
Cc: openjfx-***@openjdk.java.net
Betreff: Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.

So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.

-- Kevin
Post by marcel Austenfeld
Hello Kevin,
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
 
marcel Austenfeld
2018-10-05 07:10:44 UTC
Permalink
Kevin Rushforth
2018-10-05 11:20:07 UTC
Permalink
Thanks.

-- Kevin
Post by marcel Austenfeld
I created a bug report on https://bugs.java.com/
Bug ID is: 9057517
*Gesendet:* Donnerstag, 04. Oktober 2018 um 16:13 Uhr
*Betreff:* Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.
So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.
-- Kevin
Post by marcel Austenfeld
Hello Kevin,
"java.lang.IllegalStateException: Toolkit already initialized".
Post by marcel Austenfeld
However I found out that this error only occurs if I call SWT
FXCanvas classes located in different Eclipse plugins.
Post by marcel Austenfeld
I can create multiple JavaFX canvas if they are located in one
Eclipse plugin.
Post by marcel Austenfeld
Vice versa if I try to to open the JavaFX SceneBuilder canvas which
is located in a seperate Eclipse plugin this error occurs again.
Post by marcel Austenfeld
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't
recognize an already started toolkit in another Eclipse plugin (which
was definitely the case with Java 8!).
Post by marcel Austenfeld
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for
the hard work on JavaFX.
Post by marcel Austenfeld
Post by marcel Austenfeld
I have a problem with JavaFX which in my case is embedded in a Rich
Client Platform of Eclipse.
Post by marcel Austenfeld
Post by marcel Austenfeld
I integrated several SWT FXCanvas (some with SwingNode panels as a
SWT_AWT replacement) into my app.
Post by marcel Austenfeld
Post by marcel Austenfeld
This works fine in Java 8 which my current release depends on.
However in Java 11 after the second panel is initialized at startup
"Caused by: java.lang.IllegalStateException: Toolkit already
initialized"
Post by marcel Austenfeld
Post by marcel Austenfeld
Is there a new option available to avoid a new initialization of
the toolkit if several FXCanvas are embedded in an application?
Post by marcel Austenfeld
Post by marcel Austenfeld
Or do you now any changes since Java 8 which could the cause of
such an exception?
Post by marcel Austenfeld
Post by marcel Austenfeld
Thanks in advance for any help.
marcel Austenfeld
2018-10-05 07:15:26 UTC
Permalink
I created a bug report on https://bugs.java.com/
 
Bug ID is: 9057517
 
 
 

Gesendet: Donnerstag, 04. Oktober 2018 um 16:13 Uhr
Von: "Kevin Rushforth" <***@oracle.com>
An: "marcel Austenfeld" <***@web.de>
Cc: openjfx-***@openjdk.java.net
Betreff: Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.

So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.

-- Kevin
Post by marcel Austenfeld
Hello Kevin,
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
  
 
marcel Austenfeld
2018-10-05 10:55:31 UTC
Permalink
Bug (now ID is: 8211754) can be found here:
 
https://bugs.java.com/view_bug.do?bug_id=8211754
 

Gesendet: Donnerstag, 04. Oktober 2018 um 16:13 Uhr
Von: "Kevin Rushforth" <***@oracle.com>
An: "marcel Austenfeld" <***@web.de>
Cc: openjfx-***@openjdk.java.net
Betreff: Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.

So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.

-- Kevin
Post by marcel Austenfeld
Hello Kevin,
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
 
Kevin Rushforth
2018-10-05 11:54:20 UTC
Permalink
Or more directly, here:

https://bugs.openjdk.java.net/browse/JDK-8211754

-- Kevin
Post by marcel Austenfeld
https://bugs.java.com/view_bug.do?bug_id=8211754
Gesendet: Donnerstag, 04. Oktober 2018 um 16:13 Uhr
Betreff: Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
I think I see what caused this. In FX 8 we called FXCanvas::initFx from
the constructor of every FXCanvas. It then called an internal startup
method, PlatformImpl::startup, that permits calling it when the Toolkit
is already initialized, turning it into a runLater if it is. As part of
the refactoring for FX 9 I changed it to call FXCanvas::initFx one time
from the static block. At the same time, I changed the startup call to
use the public Platform::startup method. This change was necessary
because the javafx.swt module does not have the needed qualified exports
to call internal methods until after initialization. The public
Platform::startup method is specified to throw an exception if called
more than once.
So if the FXCanvas class is loaded more than once, for example, if it is
called from different ClassLoaders, then that would cause the problem.
Please file a bug and I'll take a look at it. It might be as simple as
wrapping the call to Platform::startup in a try/catch and calling
Platform::runLater in the catch block.
-- Kevin
Post by marcel Austenfeld
Hello Kevin,
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
Maybee this has something to do with the new module system of Java >=9?
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
Tom Schindl
2018-10-04 14:44:29 UTC
Permalink
Hi,

Just to make sure I understand. Do you say that other OSGi-Bundles bring
with them their own FXCanvas?

I've been looking at the e(fx)clipse code [1] who deals with FXCanvas,
... but I can't think of a situation where we create multiple classloaders.

Tom

[1]
https://github.com/eclipse/efxclipse-rt/blob/3.x/modules/core/org.eclipse.fx.osgi/src/main/java/org/eclipse/fx/osgi/fxloader/FXClassLoader.java
Post by marcel Austenfeld
Hello Kevin,
 
I still have problems with the error: "java.lang.IllegalStateException: Toolkit already initialized".
 
However I found out that this error only occurs if I call SWT FXCanvas classes located in different Eclipse plugins.
 
I can create multiple JavaFX canvas if they are located in one Eclipse plugin.
 
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is located in a seperate Eclipse plugin this error occurs again.
 
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't recognize an already started toolkit in another Eclipse plugin (which was definitely the case with Java 8!).
 
Maybee this has something to do with the new module system of Java >=9?
 
 
 
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the hard work on JavaFX.
I have a problem with JavaFX which in my case is embedded in a Rich Client Platform of Eclipse.
I integrated several SWT FXCanvas (some with SwingNode panels as a SWT_AWT replacement) into my app.
This works fine in Java 8 which my current release depends on.
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the toolkit if several FXCanvas are embedded in an application?
Or do you now any changes since Java 8 which could the cause of such an exception?
Thanks in advance for any help.
 
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
marcel Austenfeld
2018-10-05 06:46:40 UTC
Permalink
Tom Schindl
2018-10-05 07:27:51 UTC
Permalink
So how do you then load FXCanvas? It will not be found on any classpath
unless you ship the FXCanvas class directly which as you see is a bad idea.

I'm naturally biased but I think the approach take by e(fx)clipse is the
right one as it makes sure there's ever only one instance of FXCanvas
loaded in your runtime.

There is more static stuff in FXCanvas (eg Transfer and DropTargets) who
might or might not cause problems.

BTW IIRC the SceneBuilder Eclipse integration [1] is using e(fx)clipse
to load the FXCanvas.

Tom

[1]https://gitlab.stud.iie.ntnu.no/tobiaas/scene-builder-plugin
Hello Tom,
 
thanks for the answer. However I don't use e(fx)clipse to integrate
Javafx panels in SWT and a Rich Client Platform.
 
I believe that Kevin found the problem related to different classloaders
 
*Gesendet:* Donnerstag, 04. Oktober 2018 um 16:44 Uhr
*Betreff:* Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
Hi,
Just to make sure I understand. Do you say that other OSGi-Bundles bring
with them their own FXCanvas?
I've been looking at the e(fx)clipse code [1] who deals with FXCanvas,
... but I can't think of a situation where we create multiple classloaders.
Tom
[1]
https://github.com/eclipse/efxclipse-rt/blob/3.x/modules/core/org.eclipse.fx.osgi/src/main/java/org/eclipse/fx/osgi/fxloader/FXClassLoader.java
Post by marcel Austenfeld
Hello Kevin,
 
"java.lang.IllegalStateException: Toolkit already initialized".
Post by marcel Austenfeld
 
However I found out that this error only occurs if I call SWT FXCanvas
classes located in different Eclipse plugins.
Post by marcel Austenfeld
 
I can create multiple JavaFX canvas if they are located in one Eclipse
plugin.
Post by marcel Austenfeld
 
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is
located in a seperate Eclipse plugin this error occurs again.
Post by marcel Austenfeld
 
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't
recognize an already started toolkit in another Eclipse plugin (which
was definitely the case with Java 8!).
Post by marcel Austenfeld
 
Maybee this has something to do with the new module system of Java >=9?
 
 
 
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the
hard work on JavaFX.
Post by marcel Austenfeld
Post by marcel Austenfeld
I have a problem with JavaFX which in my case is embedded in a Rich
Client Platform of Eclipse.
Post by marcel Austenfeld
Post by marcel Austenfeld
I integrated several SWT FXCanvas (some with SwingNode panels as a
SWT_AWT replacement) into my app.
Post by marcel Austenfeld
Post by marcel Austenfeld
This works fine in Java 8 which my current release depends on.
However in Java 11 after the second panel is initialized at startup I
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the
toolkit if several FXCanvas are embedded in an application?
Post by marcel Austenfeld
Post by marcel Austenfeld
Or do you now any changes since Java 8 which could the cause of such
an exception?
Post by marcel Austenfeld
Post by marcel Austenfeld
Thanks in advance for any help.
 
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
marcel Austenfeld
2018-10-05 08:18:58 UTC
Permalink
Hello Tom,
 
I wrote you a few years ago in the e(fx)clipse forum (2014) that I implemented the SceneBuilder as an Eclipse plugin (please scroll down), see:
 
https://www.eclipse.org/forums/index.php/t/796180/

YouTube:




 
The SceneBuilder Kit is integrated into a scientific RCP application (statistics, image analysis, modeling environment, etc.) which I develop since 2004:
 
https://bio7.org
 
One feature of this application is to compile Java dynamically (in process compilation) and to create Java GUI's with JavaFX or SWT on the fly. Here an older overview of Bio7:
 


The idea behind the integration and dynamic compilation is to allow other users to create easily software inside Bio7 reusing all integrated API's
(R statistics, ImageJ, Java Scientific libs, SWT, JavaFX etc.) and special modeling components (Custom perspective and views, etc.) in an very easy way.

The integration of JavaFX is done in the plugins via the Bundle-ClassPath as described in the e(fx)clipse forum above (Java 11 will be bundled with the RCP!):

Bundle-ClassPath:
bin/,
src/,
external:$java.home$/lib/javafx-swt.jar,


This worked for years and even now (with the exception of the classloader bug analyzed by Kevin)
 

Gesendet: Freitag, 05. Oktober 2018 um 09:27 Uhr
Von: "Tom Schindl" <***@bestsolution.at>
An: open <openjfx-***@openjdk.java.net>
Betreff: Re: Aw: Re: Re: "Toolkit already initialized" error with OpenJDK 11
So how do you then load FXCanvas? It will not be found on any classpath
unless you ship the FXCanvas class directly which as you see is a bad idea.

I'm naturally biased but I think the approach take by e(fx)clipse is the
right one as it makes sure there's ever only one instance of FXCanvas
loaded in your runtime.

There is more static stuff in FXCanvas (eg Transfer and DropTargets) who
might or might not cause problems.

BTW IIRC the SceneBuilder Eclipse integration [1] is using e(fx)clipse
to load the FXCanvas.

Tom

[1]https://gitlab.stud.iie.ntnu.no/tobiaas/scene-builder-plugin
Hello Tom,
 
thanks for the answer. However I don't use e(fx)clipse to integrate
Javafx panels in SWT and a Rich Client Platform.
 
I believe that Kevin found the problem related to different classloaders
 
*Gesendet:* Donnerstag, 04. Oktober 2018 um 16:44 Uhr
*Betreff:* Re: Aw: Re: "Toolkit already initialized" error with OpenJDK 11
Hi,
Just to make sure I understand. Do you say that other OSGi-Bundles bring
with them their own FXCanvas?
I've been looking at the e(fx)clipse code [1] who deals with FXCanvas,
... but I can't think of a situation where we create multiple classloaders.
Tom
[1]
https://github.com/eclipse/efxclipse-rt/blob/3.x/modules/core/org.eclipse.fx.osgi/src/main/java/org/eclipse/fx/osgi/fxloader/FXClassLoader.java[https://github.com/eclipse/efxclipse-rt/blob/3.x/modules/core/org.eclipse.fx.osgi/src/main/java/org/eclipse/fx/osgi/fxloader/FXClassLoader.java]
Post by marcel Austenfeld
Hello Kevin,
 
"java.lang.IllegalStateException: Toolkit already initialized".
Post by marcel Austenfeld
 
However I found out that this error only occurs if I call SWT FXCanvas
classes located in different Eclipse plugins.
Post by marcel Austenfeld
 
I can create multiple JavaFX canvas if they are located in one Eclipse
plugin.
Post by marcel Austenfeld
 
Vice versa if I try to to open the JavaFX SceneBuilder canvas which is
located in a seperate Eclipse plugin this error occurs again.
Post by marcel Austenfeld
 
So I wonder that beginning with Java 9 the JavaFX toolkit doesn't
recognize an already started toolkit in another Eclipse plugin (which
was definitely the case with Java 8!).
Post by marcel Austenfeld
 
Maybee this has something to do with the new module system of Java >=9?
 
 
 
Gesendet: Mittwoch, 26. September 2018 um 14:09 Uhr
Betreff: Re: "Toolkit already initialized" error with OpenJDK 11
I'm' not aware of anything that intentionally changed between FX in JDK
8 and FX 11, but my guess is that the FX runtime is being shutdown after
your first FXCanvas exits. Try making the following call (only needed
    Platform.setImplicitExit(false);
-- Kevin
Post by marcel Austenfeld
First of all congratulation to the new release and thank you for the
hard work on JavaFX.
Post by marcel Austenfeld
Post by marcel Austenfeld
I have a problem with JavaFX which in my case is embedded in a Rich
Client Platform of Eclipse.
Post by marcel Austenfeld
Post by marcel Austenfeld
I integrated several SWT FXCanvas (some with SwingNode panels as a
SWT_AWT replacement) into my app.
Post by marcel Austenfeld
Post by marcel Austenfeld
This works fine in Java 8 which my current release depends on.
However in Java 11 after the second panel is initialized at startup I
"Caused by: java.lang.IllegalStateException: Toolkit already initialized"
Is there a new option available to avoid a new initialization of the
toolkit if several FXCanvas are embedded in an application?
Post by marcel Austenfeld
Post by marcel Austenfeld
Or do you now any changes since Java 8 which could the cause of such
an exception?
Post by marcel Austenfeld
Post by marcel Austenfeld
Thanks in advance for any help.
 
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
--
Tom Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7. A-6020 Innsbruck
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
marcel Austenfeld
2018-09-26 13:31:10 UTC
Permalink
Hello Kevin,

I already use Platform.setImplicitExit(false) at startup so this can't be the problem. All SWT FXCanvas are not closed (at least at startup).

Could it be that the initialisation of the SWT FXCanvas is different and could cause the problem.

At the moment I use as java arguments:

--module-path C:\javafx-sdk-11\lib --add-modules javafx.controls,javafx.swing,javafx.swt

The javafx.swt module is accepted but I have to add the javafx-swt.jar to my classpath to get at least an embedded canvas working.

Without the *.jar it won't work at all.

Is there a better or recommended option to include the javafx-swt.jar classes at startup in the --add-modules option?

The --add-modules javafx.swt doesn't seem to work.
Loading...