Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Embedding JavaFX in SWT E4 RCP application doesn't work(FXViewPart is empty and FXCanvas class can't even be found)
Embedding JavaFX in SWT E4 RCP application doesn't work [message #1411098] Fri, 22 August 2014 11:34 Go to next message
Philippe SFriend
Messages: 2
Registered: August 2014
Junior Member
I have an E4 RCP application using SWT, built with Eclipse Luna and running on Debian 7.6 64-bit. My goal is to embed JavaFX into this application.

I downloaded JDK 8 from the Oracle site, unzipped it, provided the path to the -vm parameter in eclipse.ini, added it to the installed JREs in Eclipse and set it for my application plug-in and product.

I added e(fx)clipse from http://download.eclipse.org/efxclipse/updates-released/1.0.0/site to my Luna installation, selecting all items. I also added "RCP 3.x Target Platform" and "Target Platform" from http://download.eclipse.org/efxclipse/runtime-nightly/site to the target platform.

I added the following plug-ins to the dependencies:

  • org.eclipse.fx.ui.workbench3
  • org.eclipse.fx.javafx

And the following features to the product:

  • org.eclipse.fx.target.rcp.feature
  • org.eclipse.rcp

Based on e(fx)clipse tutorial no. 2, I added -Dosgi.framework.extensions=org.eclipse.fx.osgi to the VM arguments and the following part to my part stack:
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;

import org.eclipse.fx.ui.workbench3.FXViewPart;

public class JavaFxPart extends FXViewPart {
	private Button button;
	
	@Override
	protected Scene createFxScene() {
		BorderPane pane = new BorderPane();
		button = new Button("test");
		pane.setCenter(button);
		return new Scene(pane);
	}

	@Override
	protected void setFxFocus() {
		button.requestFocus();
	}
}

However, that part doesn't display anything. Debugging also shows that createFxScene is not entered.

Alternatively, I tried to use FXCanvas (wouldn't it be better anyway to use this instead of a view part based on E3?), but the class can't be found.

What am I doing wrong?
Re: Embedding JavaFX in SWT E4 RCP application doesn't work [message #1411138 is a reply to message #1411098] Fri, 22 August 2014 13:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On FXViewPart:
--------------
First of all is the application you develop a pure e4 application?
FXViewPart only makes sense in an Compat-e4 application.


On FXCanvas:
------------
So did you added a package import for javafx.embedd.swt? Did you try
lauching with -Defxclipse.osgi.hook.debug=true to see if the adapter
hook is loaded?


On usage in pure e4+SWT:
------------------------
In case you have a pure e4 application simply:
a) add
- org.eclipse.fx.ui.di.interopt
- org.eclipse.fx.javafx
- org.eclipse.fx.osgi
to your launch config

b) launch the application with -Defxclipse.osgi.hook.debug=true
c) Simply develop a pure JavaFX Part like this

public class TestFX {
@PostConstruct
public void init(BorderPane p) {
// write your javafx code
}
}


I would suggest to have the parts who are implemented in javafx in
an extra bundle which has NO swt dependency but only does package
imports for javafx!


Tom


Tom

On 22.08.14 14:51, Philippe S wrote:
> I have an E4 RCP application using SWT, built with Eclipse Luna and
> running on Debian 7.6 64-bit. My goal is to embed JavaFX into this
> application.
>
> I downloaded JDK 8 from the Oracle site, unzipped it, provided the path
> to the -vm parameter in eclipse.ini, added it to the installed JREs in
> Eclipse and set it for my application plug-in and product.
>
> I added e(fx)clipse from
> http://download.eclipse.org/efxclipse/updates-released/1.0.0/site to my
> Luna installation, selecting all items. I also added "RCP 3.x Target
> Platform" and "Target Platform" from
> http://download.eclipse.org/efxclipse/runtime-nightly/site to the target
> platform.
>
> I added the following plug-ins to the dependencies:
>
> org.eclipse.fx.ui.workbench3
> org.eclipse.fx.javafx
>
> And the following features to the product:
>
> org.eclipse.fx.target.rcp.feature
> org.eclipse.rcp
>
> Based on https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial2, I added
> -Dosgi.framework.extensions=org.eclipse.fx.osgi to the VM arguments and
> the following part to my part stack:
> import javafx.scene.Scene;
> import javafx.scene.control.Button;
> import javafx.scene.layout.BorderPane;
>
> import org.eclipse.fx.ui.workbench3.FXViewPart;
>
> public class JavaFxPart extends FXViewPart {
> private Button button;
>
> @Override
> protected Scene createFxScene() {
> BorderPane pane = new BorderPane();
> button = new Button("test");
> pane.setCenter(button);
> return new Scene(pane);
> }
>
> @Override
> protected void setFxFocus() {
> button.requestFocus();
> }
> }
> However, that part doesn't display anything. Debugging also shows that
> createFxScene is not entered.
>
> Alternatively, I tried to use FXCanvas (wouldn't it be better anyway to
> use this instead of a view part based on E3?), but the class can't be
> found.
>
> What am I doing wrong?
Re: Embedding JavaFX in SWT E4 RCP application doesn't work [message #1411139 is a reply to message #1411138] Fri, 22 August 2014 13:43 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
one more note. On Linux JavaFX will only be loaded if your SWT is
running with Gtk2, JavaFX fails when SWT runs on Gtk3
-Defxclipse.osgi.hook.debug=true will spit out informations if this is
the case.

You need to force SWT to Gtk2 by setting SWT_GTK3=0 in your env.

Tom

On 22.08.14 15:41, Tom Schindl wrote:
> On FXViewPart:
> --------------
> First of all is the application you develop a pure e4 application?
> FXViewPart only makes sense in an Compat-e4 application.
>
>
> On FXCanvas:
> ------------
> So did you added a package import for javafx.embedd.swt? Did you try
> lauching with -Defxclipse.osgi.hook.debug=true to see if the adapter
> hook is loaded?
>
>
> On usage in pure e4+SWT:
> ------------------------
> In case you have a pure e4 application simply:
> a) add
> - org.eclipse.fx.ui.di.interopt
> - org.eclipse.fx.javafx
> - org.eclipse.fx.osgi
> to your launch config
>
> b) launch the application with -Defxclipse.osgi.hook.debug=true
> c) Simply develop a pure JavaFX Part like this
>
> public class TestFX {
> @PostConstruct
> public void init(BorderPane p) {
> // write your javafx code
> }
> }
>
>
> I would suggest to have the parts who are implemented in javafx in
> an extra bundle which has NO swt dependency but only does package
> imports for javafx!
>
>
> Tom
>
>
> Tom
>
> On 22.08.14 14:51, Philippe S wrote:
>> I have an E4 RCP application using SWT, built with Eclipse Luna and
>> running on Debian 7.6 64-bit. My goal is to embed JavaFX into this
>> application.
>>
>> I downloaded JDK 8 from the Oracle site, unzipped it, provided the path
>> to the -vm parameter in eclipse.ini, added it to the installed JREs in
>> Eclipse and set it for my application plug-in and product.
>>
>> I added e(fx)clipse from
>> http://download.eclipse.org/efxclipse/updates-released/1.0.0/site to my
>> Luna installation, selecting all items. I also added "RCP 3.x Target
>> Platform" and "Target Platform" from
>> http://download.eclipse.org/efxclipse/runtime-nightly/site to the target
>> platform.
>>
>> I added the following plug-ins to the dependencies:
>>
>> org.eclipse.fx.ui.workbench3
>> org.eclipse.fx.javafx
>>
>> And the following features to the product:
>>
>> org.eclipse.fx.target.rcp.feature
>> org.eclipse.rcp
>>
>> Based on https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial2, I added
>> -Dosgi.framework.extensions=org.eclipse.fx.osgi to the VM arguments and
>> the following part to my part stack:
>> import javafx.scene.Scene;
>> import javafx.scene.control.Button;
>> import javafx.scene.layout.BorderPane;
>>
>> import org.eclipse.fx.ui.workbench3.FXViewPart;
>>
>> public class JavaFxPart extends FXViewPart {
>> private Button button;
>>
>> @Override
>> protected Scene createFxScene() {
>> BorderPane pane = new BorderPane();
>> button = new Button("test");
>> pane.setCenter(button);
>> return new Scene(pane);
>> }
>>
>> @Override
>> protected void setFxFocus() {
>> button.requestFocus();
>> }
>> }
>> However, that part doesn't display anything. Debugging also shows that
>> createFxScene is not entered.
>>
>> Alternatively, I tried to use FXCanvas (wouldn't it be better anyway to
>> use this instead of a view part based on E3?), but the class can't be
>> found.
>>
>> What am I doing wrong?
>
Re: Embedding JavaFX in SWT E4 RCP application doesn't work [message #1412167 is a reply to message #1411138] Mon, 25 August 2014 13:07 Go to previous message
Philippe SFriend
Messages: 2
Registered: August 2014
Junior Member
Thanks for your hints, I found the root of the problem in the meantime:
Bundle-RequiredExecutionEnvironment in the manifest file was set to JavaSE-1.7. Only after setting it to JavaSE-1.8, jfxswt.jar has been added automatically to the application plug-in dependencies. This allowed me to finally use FXCanvas:
@PostConstruct
public void createControls(Composite parent) {

[...]		

	final FXCanvas fxCanvas = new FXCanvas(parent, SWT.NONE) {
		public Point computeSize(int wHint, int hHint, boolean changed) {
			getScene().getWindow().sizeToScene();
			int width = (int) getScene().getWidth();
			int height = (int) getScene().getHeight();
			return new Point(width, height);
		}
	};
	javafx.scene.Group group = new javafx.scene.Group();
	final javafx.scene.control.Button jfxButton = new javafx.scene.control.Button("JFX Button");
	jfxButton.setStyle("-fx-background-color: linear-gradient(#ff5400, #be1d00); " + "-fx-background-radius: 30; " + "-fx-background-insets: 0; " + "-fx-text-fill: white;");
	group.getChildren().add(jfxButton);
	Scene scene = new Scene(group, Color.rgb(parent.getBackground().getRed(), parent.getBackground().getGreen(), parent.getBackground().getBlue()));
	fxCanvas.setScene(scene);

[...]


I'll comment on your reply in case other people with similar problems find this thread.

Quote:
First of all is the application you develop a pure e4 application?
FXViewPart only makes sense in an Compat-e4 application.

Yes, it's pure E4. That's why I asked about the usefulness of FXViewPart in this case. Thanks for the clarification, now I don't need to worry that this still doesn't work.

Quote:
So did you added a package import for javafx.embedd.swt?

It was imported via the org.eclipse.fx.javafx plug-in, so I couldn't even add it to the Imported Packages list.

Quote:
Did you try
lauching with -Defxclipse.osgi.hook.debug=true to see if the adapter
hook is loaded?

I had tried launching with that VM argument before, but it didn't have any effect on the output. Now there are indeed messages from FXClassLoader etc.

Quote:
a) add
- org.eclipse.fx.ui.di.interopt
- org.eclipse.fx.javafx
- org.eclipse.fx.osgi
to your launch config

org.eclipse.fx.osgi seems to be a fragment which I couldn't add to the dependencies. org.eclipse.fx.ui.di.interopt was not needed to make my FXCanvas example run.

Quote:
c) Simply develop a pure JavaFX Part like this

public class TestFX {
@PostConstruct
public void init(BorderPane p) {
// write your javafx code
}
}

I would suggest to have the parts who are implemented in javafx in
an extra bundle which has NO swt dependency but only does package
imports for javafx!

Thanks, these are useful hints for future development of the application.

Quote:
You need to force SWT to Gtk2 by setting SWT_GTK3=0 in your env.

Good comment, I have to do this anyway for Eclipse Luna because otherwise the whole IDE wouldn't even start.
Previous Topic:Popups in FXCanvas do not disappear on focus lost events
Next Topic:Canvas is not a valid type
Goto Forum:
  


Current Time: Fri Apr 26 16:49:35 GMT 2024

Powered by FUDForum. Page generated in 0.03203 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top