As a result of a custom Intellij action plugin developer can popup a dialog window with a custom UI. I am developing UI using JavaFX embedded into Swing panel.
JavaFX wise everything works fine. The problem is plugin class loader. It can't find any JavaFX class despite the fact that the IDEA version is 12.1.3 and JDK is 1.7.0_21. If I add jfxrt.jar as a compile dependency then everything works fine but it doesn't sound right to bring a standard jar together with a plugin.
Question: What is the correct way of adding JavaFX as the dependency of a plugin?
To be able to work with JavaFX in IntelliJ IDEA, the JavaFX bundled plugin must be enabled: In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Plugins. Switch to the Installed tab and make sure that the JavaFX plugin is enabled. If the plugin is disabled, select the checkbox next to it.
Click on the File menu and select Project Structure . In the dialog that appears, select the Libraries tab and click the + icon to add a new Java library: Find your javafx-sdk folder and select the lib subfolder: Click the OK button to complete the process.
From a Java developer perspective, both technologies are highly useful in writing pluggable UI components. With its vast UI component library, Swing can provide added advantage to the developer, whereas when it comes to design modern and rich internet application, JavaFX can supersede Swing.
Starting with JDK 11, Oracle will remove JavaFX from the JDK, though will continue to provide commercial support for it in Oracle JDK 8 at least until 2022, according to Oracle's blog. The technology, which is used to write cross platform, rich-client applications, will become available as a separate download.
Three years and four IntelliJ versions (v16) later i will give everybody a hint how to use JavaFx in plugin development.
As an example, the following code demonstrates how to create a ToolWindow with JavaFx components:
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
public class TestToolWindowFactory
implements ToolWindowFactory
{
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow)
{
final JFXPanel fxPanel = new JFXPanel();
JComponent component = toolWindow.getComponent();
Platform.setImplicitExit(false);
Platform.runLater(() -> {
Group root = new Group();
Scene scene = new Scene(root, Color.ALICEBLUE);
Text text = new Text();
text.setX(40);
text.setY(100);
text.setFont(new Font(25));
text.setText("Welcome JavaFX!");
root.getChildren().add(text);
fxPanel.setScene(scene);
});
component.getParent().add(fxPanel);
}
}
Note: Because of JDK-8090517, it is important to invoke:
Platform.setImplicitExit(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With