-1

in my JavaApplication I have a JLayeredPane in my JFrame. The JLayeredPane contains a Canvas as a lower panel where I display a Video with a videoplayer framework. On an upper level the JLayeredPane contains an JFXPanel where I display a JavaFX.WebView. The Webview is complete transparent.

The problem is that the Canvas is only visible where the WebView is not diplayed and I see the background from the JFrame where the WebView is placed. If I disable the JFXPanel I can see the whole Canvas with the video.

I also tried to add a JPanel as the lower Level. The result was like I want to be the Canvas. I can see the complete JPanel and on top of it, it displays the WebView.

So, what can I do to make the Canvas be strong enough to display all-over the Frame. I think canvas.setOpaque would fix the problem but this Method is not available.

UPDATE:

    //BROWSER
    this.jfxPanel = new JFXPanel();
    this.jfxPanel.setOpaque(false);
    this.jfxPanel.setBounds(0,0,MainFrame.VIDEO_SIZE_X,MainFrame.VIDEO_SIZE_Y);

    PlatformImpl.startup(new Runnable() {
        public void run() {
            webView = new WebView();
            webView.setPrefSize(MainFrame.VIDEO_SIZE_X-100,MainFrame.VIDEO_SIZE_Y-100);
            webEngine = webView.getEngine();
            webView.setStyle("-fx-background-color: rgba(0,0,0,0)");

            Scene scene = new Scene(webView,MainFrame.VIDEO_SIZE_X-100,MainFrame.VIDEO_SIZE_Y-100);
            scene.setFill(javafx.scene.paint.Color.TRANSPARENT);

            webEngine.documentProperty().addListener(new DocListener());

            webEngine.loadContent("<body style='background : rgba(0,0,0,0);font-size: 70px;text-align:center;'>Test Transparent</body>");

            jfxPanel.setScene(scene);
        }
    });
    //add browser in upper level to JLayeredPane  
    this.videoPanel.add(jfxPanel, new Integer(100));

    //CANVAS
    this.videoCanvas = new Canvas();
    this.videoCanvas.setVisible(true);
    this.videoCanvas.setBounds(0,0, MainFrame.VIDEO_SIZE_X,MainFrame.VIDEO_SIZE_Y);
    //add canvas at lower level to JLayeredPane
    this.videoPanel.add(this.videoCanvas, new Integer(0));

The videoPanel is the JLayeredPane. It is setVisible(true) and has the same size like canvas and the browser.

Thanks in advance!

Criska
  • 17
  • 4

1 Answers1

1

As was already mentioned by Gilbert Le Blanc, mixing AWT, Swing, and JavaFX components might complicate your project unnecessarily (see mixing awt and swing in GUI programming using Java and JavaFX Tip 9: Do Not Mix Swing / JavaFX). If you could find a Swing based web viewer and video player, it would make it easier to make it work.

You can for example look at The DJ Project for both the web viewer and the video player (see also Best Java/Swing browser component?). The Java Media Framework (JMF), xuggle, and the VLC Java bindings are other options for the video player (see also A simple way of embedding a video in my Swing GUI).

Finally, a complete and working example would be helpful to see what is and what is not working at the moment, and it would be helpful as a starting point to suggest improvements (please look at https://stackoverflow.com/help/mcve).

Community
  • 1
  • 1
Freek de Bruijn
  • 3,552
  • 2
  • 22
  • 28