-1

I want to use a JFXPanel for a video player. I use a fxml file for the design of the appplication. (not for the videoplayer itself)

...
<VBox>
      <Pane id="VideoEmbedded" fx:id="VideoEmbedded" style="- fx-background-color: #111111;" VBox.vgrow="ALWAYS" />
      <HBox alignment="CENTER" prefWidth="600.0" spacing="8.0" />        
 </VBox>
...

I want simply to "replace" means fill the Pane("VideoEmbedded") with my JFXPanel.

//inside the controller
final JFXPanel JFXPanel_VideoEmbedded= new JFXPanel();

@FXML
private JPanel VideoEmbedded;
...
//inside the videoplayer function
VideoEmbedded.add(JFXPanel_VideoEmbedded); //this doesn't work

How can i add the JFXPanel into the correct position in the DOM-Hirarchy?

user3776738
  • 214
  • 2
  • 10
  • 27
  • I don't understand why your `JPanel` is defined in your Controller class. Are you defining it in the FXML? If so, how are you managing the threading issues described in the [documentation](http://docs.oracle.com/javase/8/javafx/api/index.html)? (And if not, why is it annotated `@FXML` and how are you initializing it?) And also... your FXML file defines `VideoEmbedded` as a `Pane` but your controller declares it as a `JPanel`, which is obviously incompatible. – James_D Jan 22 '16 at 16:36
  • So it's really unclear (to put it mildly) what you're trying to do from these tiny code snippets. Can you explain what you're actually trying to achieve? Why do you need to mix swing components and JavaFX components? – James_D Jan 22 '16 at 16:39
  • okay my intention is to show a video in the pane. But i believe it is only possible in JFXPanels.i fought by defning it i have access to the Pane with the same fx:id in my fxml file.so i can say VideoEmmbeded take the JFXPanel inside of you so i can see it and it can play the video.(i just can hear the audio right now) In Jquery i would just do $('#JFXPanel_VideoEmbedded').appendTo("#VideoEmbedded"); – user3776738 Jan 22 '16 at 16:57
  • That's not at all true. The JavaFX component that plays video is a `MediaView` (it uses a `MediaPlayer` and a `Media`). It can be placed anywhere you need it in a JavaFX scene graph, e.g. in a `VBox` etc. A `JFXPanel` is for embedding a JavaFX scene into a Swing application; it's a Swing component that can display a JavaFX Scene. If you don't need to mix swing and JavaFX, don't: you have a lot of tricky multithreading to work around. Just use a pure JavaFX application. [Tutorial](http://docs.oracle.com/javase/8/javafx/media-tutorial/simpleplayer.htm) – James_D Jan 22 '16 at 17:05
  • so i can view the video in a normal pane? – user3776738 Jan 22 '16 at 17:08
  • 1
    Yes. A `MediaView` is a subclass of `Node`; it can be added to a `Pane` or any subclass (from your FXML it looks like you want it in a `VBox`). – James_D Jan 22 '16 at 17:10
  • can use Pane like Pane.setScene(scene); ? – user3776738 Jan 22 '16 at 17:12
  • Huh? No. That doesn't make any sense. Why don't you work through some basic JavaFX tutorials and see how the pieces fit together. The link I posted two comments ago has a complete class that displays a video. – James_D Jan 22 '16 at 17:13
  • Yes,but isn't that just inside Jframe which is a seperate window? i want it inside the pane.i can't find anything about that. – user3776738 Jan 22 '16 at 17:18
  • OK, again, why are you mixing swing with JavaFX???? – James_D Jan 22 '16 at 17:18
  • I'm so sorry.Now i got it. You have said it before.I have to use MediaView for my Videoplayer.Sorry – user3776738 Jan 22 '16 at 17:33

2 Answers2

1

you are mixing Java Swing and JavaFX (older technology and newer technology) the JPanel VideoEmbedded is Java Swing the JFXPanel JFXPanel_VideoEmbedded is JavaFX

see this thread Adding JFXPanel to a JFrame. Why is it not working? and the links above

Community
  • 1
  • 1
ralf htp
  • 9,149
  • 4
  • 22
  • 34
0
 panel.add(jfxPanel, BorderLayout.CENTER);

see https://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm

or use JavaFX Scene Builder (Eclipse, Netbeans,...)

ralf htp
  • 9,149
  • 4
  • 22
  • 34