Java Code Examples for javafx.embed.swing.JFXPanel#setScene()

The following examples show how to use javafx.embed.swing.JFXPanel#setScene() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SamplesTableView.java    From megan-ce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * initialize JavaFX
 *
 * @param jfxPanel
 */
private void initFxLater(JFXPanel jfxPanel) {
    if (!initialized) {
        if (Thread.getDefaultUncaughtExceptionHandler() != fxExceptionHandler)
            Thread.setDefaultUncaughtExceptionHandler(fxExceptionHandler);
        synchronized (lock) {
            if (!initialized) {
                try {
                    final BorderPane rootNode = new BorderPane();
                    jfxPanel.setScene(new Scene(rootNode, 600, 600));

                    final Node main = createMainNode();
                    rootNode.setCenter(main);
                    BorderPane.setMargin(main, new Insets(3, 3, 3, 3));

                    // String css = NotificationsInSwing.getControlStylesheetURL();
                    // if (css != null)
                    //    jfxPanel.getScene().getStylesheets().add(css);
                } finally {
                    initialized = true;
                }
            }
        }
    }
}
 
Example 2
Source File: Main.java    From TweetwallFX with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    queryTextfield = new JTextField("#javaone");
    tweetwall = new EmbeddedTweetwall();

    final JFXPanel p = new JFXPanel();
    p.setScene(new Scene(new BorderPane(tweetwall)));

    queryTextfield.addActionListener(e -> {
        stop();
        start(queryTextfield.getText());
    });

    panel.add(queryTextfield, BorderLayout.NORTH);
    panel.add(p, BorderLayout.CENTER);

    JFrame jFrame = new JFrame("Hi there");
    jFrame.setContentPane(panel);
    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jFrame.setSize(1024, 768);
    jFrame.setVisible(true);
}
 
Example 3
Source File: JFxBuilder.java    From Weather-Forecast with Apache License 2.0 5 votes vote down vote up
private void initFX(JFXPanel fxPanel) {
    // This method is invoked on the JavaFX thread
    Group root = new Group();
    Scene scene = new Scene(root);
    fxPanel.setScene(scene);

}
 
Example 4
Source File: JavaFxHtmlToolkit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object initHtmlComponent(JComponent c, Consumer<String> titleDisplayer) {
    JFXPanel p = (JFXPanel) c;
    Platform.setImplicitExit(false);
    WebView webView = new WebView();
    BorderPane bp = new BorderPane();
    Scene scene = new Scene(bp, Color.ALICEBLUE);

    class X implements ChangeListener<String>, Runnable {

        private String title;

        public X() {
            super();
        }

        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String t1) {
            title = webView.getEngine().getTitle();
            EventQueue.invokeLater(this);
        }

        @Override
        public void run() {
            if (title != null) {
                titleDisplayer.accept(title);
            }
        }
    }
    final X x = new X();
    webView.getEngine().titleProperty().addListener(x);
    HtmlToolkit.getDefault().execute(x);
    bp.setCenter(webView);
    p.setScene(scene);
    return webView;
}
 
Example 5
Source File: ResizePolicyTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public ResizePolicy createResizePolicy() {
	// create injector
	Injector injector = Guice.createInjector(new MvcFxModule() {
		@Override
		protected void bindAbstractContentPartAdapters(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
			super.bindAbstractContentPartAdapters(adapterMapBinder);
			adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(ResizePolicy.class);
		}

		protected void bindIContentPartFactory() {
			binder().bind(IContentPartFactory.class).to(ResizePolicyTestsContentPartFactory.class);
		}

		@Override
		protected void configure() {
			super.configure();
			bindIContentPartFactory();
		}
	});
	injector.injectMembers(this);
	// get viewer
	IViewer viewer = domain.getAdapter(AdapterKey.get(IViewer.class, IDomain.CONTENT_VIEWER_ROLE));
	// hook viewer to scene
	Scene scene = new Scene(viewer.getCanvas(), 100, 100);
	JFXPanel panel = new JFXPanel();
	panel.setScene(scene);
	// set viewer contents
	Dimension content = new Dimension(0, 0);
	viewer.getContents().setAll(Collections.singletonList(content));
	// activate domain
	domain.activate();
	// get content part for the content object
	IContentPart<? extends Node> contentPart = viewer.getContentPartMap().get(content);
	// get transform policy for that part
	return contentPart.getAdapter(ResizePolicy.class);
}
 
Example 6
Source File: TransformPolicyTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public TransformPolicy createTransformPolicy() {
	// create injector
	Injector injector = Guice.createInjector(new MvcFxModule() {
		@Override
		protected void bindAbstractContentPartAdapters(MapBinder<AdapterKey<?>, Object> adapterMapBinder) {
			super.bindAbstractContentPartAdapters(adapterMapBinder);
			adapterMapBinder.addBinding(AdapterKey.defaultRole()).to(TransformPolicy.class);
		}

		protected void bindIContentPartFactory() {
			binder().bind(IContentPartFactory.class).to(TxContentPartFactory.class);
		}

		@Override
		protected void configure() {
			super.configure();
			bindIContentPartFactory();
		}
	});
	injector.injectMembers(this);
	// get viewer
	IViewer viewer = domain.getAdapter(AdapterKey.get(IViewer.class, IDomain.CONTENT_VIEWER_ROLE));
	// hook viewer to scene
	Scene scene = new Scene(viewer.getCanvas(), 100, 100);
	JFXPanel panel = new JFXPanel();
	panel.setScene(scene);
	// set viewer contents
	Point content = new Point(0, 0);
	viewer.getContents().setAll(Collections.singletonList(content));
	// activate domain
	domain.activate();
	// get content part for the content object
	IContentPart<? extends Node> contentPart = viewer.getContentPartMap().get(content);
	// get transform policy for that part
	return contentPart.getAdapter(TransformPolicy.class);
}
 
Example 7
Source File: AemdcPanel.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public void reset() {
    if(isShown()) {
        setContent(null);
        panel = new JFXPanel();
        setContent(panel);
        if(aemdcScene == null) {
            Platform.runLater(() -> {
                initFX(project);
            });
        } else {
            panel.setScene(aemdcScene);
        }
        setBorder(BorderFactory.createLineBorder(java.awt.Color.BLACK, 1, false));
    }
}
 
Example 8
Source File: MacMainMenuHybrid.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
private JFXPanel createMainFXWindow() throws Exception {
	JFXPanel jfxPanel = new JFXPanel();  //  initializes the toolkit
	FXMLLoader fxmlLoader = new FXMLLoader( this.getClass().getResource("/macmenu-fxml/MacMenu.fxml") );
	fxmlLoader.load();
	Parent p = fxmlLoader.getRoot();
	Scene scene = new Scene(p);
	jfxPanel.setScene( scene );
	return jfxPanel;
}
 
Example 9
Source File: AbstractTopsoilDisplay.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
protected void initFX(JFXPanel fxPanel) {
    // This method is invoked on the JavaFX thread
    Scene scene = createScene();
    fxPanel.setScene(scene);
    fxPanel.setSize(myDimension);

    // this forces resizing
    setLayout(new BorderLayout());
    add(fxPanel, BorderLayout.CENTER);
}
 
Example 10
Source File: JavaFX3DExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void initFx(JFXPanel fxPanel) {

      sphere = new Sphere(100);
      sphere.setLayoutX(200);
      sphere.setLayoutY(200);
      Group root = new Group(sphere);

      Scene scene = new Scene(root, 900, 600);
      fxPanel.setScene(scene);
      fxPanel.setSize(900, 600);
   }
 
Example 11
Source File: AurousFrame.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
private void initFX(final JFXPanel fxPanel) throws Throwable {
	// This method is invoked on the JavaFX thread
	final MediaPlayerScene mediaPlayerScene = new MediaPlayerScene();
	UISession.setMediaPlayerScene(mediaPlayerScene);
	scene = UISession.getMediaPlayerScene().createScene(
			"https://www.youtube.com/watch?v=kGubD7KG9FQ");
	setScene(scene);
	fxPanel.setScene(scene);
	UISession.setJFXPanel(fxPanel);

}
 
Example 12
Source File: O365InteractiveAuthenticatorFrame.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
private void initFX(final JFXPanel fxPanel, final String url, final String redirectUri) {
    WebView webView = new WebView();
    final WebEngine webViewEngine = webView.getEngine();

    final ProgressBar loadProgress = new ProgressBar();
    loadProgress.progressProperty().bind(webViewEngine.getLoadWorker().progressProperty());

    StackPane hBox = new StackPane();
    hBox.getChildren().setAll(webView, loadProgress);
    Scene scene = new Scene(hBox);
    fxPanel.setScene(scene);

    webViewEngine.setOnAlert(stringWebEvent -> SwingUtilities.invokeLater(() -> {
        String message = stringWebEvent.getData();
        JOptionPane.showMessageDialog(O365InteractiveAuthenticatorFrame.this, message);
    }));
    webViewEngine.setOnError(event -> LOGGER.error(event.getMessage()));


    webViewEngine.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
        if (newState == Worker.State.SUCCEEDED) {
            loadProgress.setVisible(false);
            location = webViewEngine.getLocation();
            updateTitleAndFocus(location);
            LOGGER.debug("Webview location: " + location);
            // override console.log
            O365InteractiveJSLogger.register(webViewEngine);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(dumpDocument(webViewEngine.getDocument()));
            }
            if (location.startsWith(redirectUri)) {
                LOGGER.debug("Location starts with redirectUri, check code");

                authenticator.isAuthenticated = location.contains("code=") && location.contains("&session_state=");
                if (!authenticator.isAuthenticated && location.contains("error=")) {
                    authenticator.errorCode = location.substring(location.indexOf("error="));
                }
                if (authenticator.isAuthenticated) {
                    LOGGER.debug("Authenticated location: " + location);
                    String code = location.substring(location.indexOf("code=") + 5, location.indexOf("&session_state="));
                    String sessionState = location.substring(location.lastIndexOf('='));

                    LOGGER.debug("Authentication Code: " + code);
                    LOGGER.debug("Authentication session state: " + sessionState);
                    authenticator.code = code;
                }
                close();
            }
        } else if (newState == Worker.State.FAILED) {
            Throwable e = webViewEngine.getLoadWorker().getException();
            if (e != null) {
                handleError(e);
            }
            close();
        }

    });
    webViewEngine.load(url);
}
 
Example 13
Source File: VirtualCursor.java    From haxademic with MIT License 4 votes vote down vote up
private void initFX(JFXPanel fxPanel) {
	// This method is invoked on the JavaFX thread
	browser = new Browser(jframe.getWidth(), jframe.getHeight());
	Scene scene = new Scene(browser, jframe.getWidth(), jframe.getHeight(), Color.web("#666970"));
	fxPanel.setScene(scene);
}