Geertjan's Blog

JavaFX MultiViewElement

Geertjan Wielenga
Product Manager

Here's my first attempt at integrating the visual JavaFX HTMLEditor on top of HTML files on the NetBeans Platform, e.g., NetBeans IDE.

All the code and note that the two sides aren't synchronized (yet):

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.HTMLEditor;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import org.netbeans.core.spi.multiview.CloseOperationState;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
import org.openide.awt.UndoRedo;
import org.openide.filesystems.FileObject;
import org.openide.util.Lookup;
import org.openide.windows.TopComponent;
@MultiViewElement.Registration(displayName = "Visual",
mimeType = {"text/xhtml", "text/html"},
persistenceType = TopComponent.PERSISTENCE_NEVER,
preferredID = "Visual",
position = 1)
public class JavaFXMVE extends JPanel implements MultiViewElement {
private FileObject obj;
private JToolBar tb = new JToolBar();
private static JFXPanel fxContainer;
public JavaFXMVE(Lookup lkp) {
this.obj = lkp.lookup(FileObject.class);
assert obj != null;
fxContainer = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
private void createScene() {
HTMLEditor htmlEditor = new HTMLEditor();
try {
} catch (IOException ex) {
Logger.getLogger(JavaFXMVE.class.getName()).log(Level.SEVERE, null, ex);
StackPane root = new StackPane();
fxContainer.setScene(new Scene(root));
public JComponent getVisualRepresentation() {
return fxContainer;
public JComponent getToolbarRepresentation() {
return tb;
public Action[] getActions() {
return new Action[0];
public Lookup getLookup() {
return obj.getLookup();
public void componentOpened() {
public void componentClosed() {
public void componentShowing() {
public void componentHidden() {
public void componentActivated() {
public void componentDeactivated() {
public UndoRedo getUndoRedo() {
return UndoRedo.NONE;
public void setMultiViewCallback(MultiViewElementCallback callback) {
public CloseOperationState canCloseElement() {
return CloseOperationState.STATE_OK;

If someone has ideas or code for synchronizing the two sides, don't be shy, leave a comment at the end of this blog entry!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.