'Swing JFrame rendering a webpage with embedded video shows a white page and throws IOException with "invalid URL"
I wonder if I do some mistakes because I do not get the content of the webpage displayed on the JFrame. Instead, I only get a white page. The error I got was:
java.io.IOException: invalid URL
Here is the code for video.html:
<iframe width="560" height="315" src="video-file.mp4" allowfullscreen></iframe>
Thanks in advance for any help!
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import javax.swing.*;
public class Vid extends JFrame{
public Vid(String title){
super(title);
setBounds(100, 100, 550, 500);
Container ControlHost = getContentPane();
ControlHost.setLayout(new FlowLayout());
JEditorPane jep = new JEditorPane();
jep.setEditable(false);
JScrollPane scroll = new JScrollPane(jep);
Dimension ScrollSize = new Dimension(500, 450);
scroll.setPreferredSize(ScrollSize);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
ControlHost.add(scroll);
URL HtmlPage = Vid.class.getResource("video.html");
try {
jep.setPage(HtmlPage);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Solution 1:[1]
Probably problem is in:
URL HtmlPage = Vid.class.getResource("video.html");
If this file is in your root-level class-path, you should ask for it:
URL HtmlPage = Vid.class.getResource("/video.html");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tchudyk |
