loading url to editor pane
Hi, i'm trying to display a html page on JEditorPane, but it can't
find this url.
code:
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
public class Menu extends JPanel
{
private static JFrame frame;
private JLayeredPane layeredPane;
private JPanel panelMenu;
private static final int SCREEN_WIDTH=600,
SCREEN_HEIGHT=600;
private int rozmiarPanela;
public Menu() {
layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(
new Dimension(SCREEN_WIDTH,
SCREEN_HEIGHT));
rozmiarPanela = 600;
Point origin = new Point(0, 0);
panelMenu = createColoredPanel(origin);
layeredPane.add(panelMenu, new Integer(4),0);
this.add(layeredPane);
////////////*code that doesnt work*//////////
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setBounds(50,50,300,400);
panelMenu.add(editorPane);
java.net.URL helpURL = Menu.class.getResource(
"http://java.sun.com/index.html");
if (helpURL != null) {
try {
editorPane.setPage(helpURL);
} catch (IOException e) {
System.err.println("Attempted to read a bad URL: " + helpURL);
}
} else {
System.err.println("Couldn't find file: index.html");
}
/*////////end of code*/////////////////
}
private JPanel createColoredPanel(Point origin){
JPanel panel =new JPanel(new GridBagLayout());
panel.setOpaque(true);
panel.setVisible(true);
panel.setBackground(Color.black);
panel.setBounds(origin.x, origin.y, rozmiarPanela , rozmiarPanela);
return panel;
}
private static void createAndShowGUI() {
frame = new JFrame("LayeredPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new Menu();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.setUndecorated(true);
frame.pack();
frame.setBounds(200,100,SCREEN_WIDTH,SCREEN_HEIGHT);
frame.setVisible(true);
frame.setResizable(false);
frame.pack();
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
JFrame.setDefaultLookAndFeelDecorated(true);
} catch (Exception ex) {
ex.printStackTrace();
}
createAndShowGUI();
}
});
}
}