0

Ok hello all, I am still learning Java and just messing about with some things, I made a GUI and have a JEditorPane to display a webpage when the "Go" button is pressed.

Code that won't work:

    private void goActionPerformed(java.awt.event.ActionEvent evt) {                                   
            String URL = url.getText();
    JEditorPane.setEditable(false);   

    try {
      JEditorPane.setPage("www.google.com");
    }catch (IOException e) {
      JEditorPane.setContentType("text/html");
      JEditorPane.setText("<html>Could not load " + URL);
    } 
}   

Anyhelp is welcome thanks!

Fusion
  • 70
  • 1
  • 10

2 Answers2

1

setPage needs a valid protocol prefix

jEditorPane.setPage("http://www.google.com");

Ensure your textfield also has a this prefix (or at least the URL link argument is well formed)

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • That got me farther but it looks like http://gyazo.com/c5b20b7a3e641e4e5a1584673eaee518 – Fusion Feb 22 '14 at 02:12
  • Yes, unfortunately `JEditorPane` only supports HTML 3.2. You could embed JavaFX's WebView. Here is Oracle's [example](http://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm) – Reimeus Feb 22 '14 at 02:16
  • Is there a way to add the webview via Swing? because this is all I have for my options. http://gyazo.com/3af0d160ca7517e73ab52e497ef6dea0 – Fusion Feb 22 '14 at 02:37
  • I understand that but I dont have a "Webview" tool for my swing. – Fusion Feb 22 '14 at 03:41
  • You mean you dont have the `WebView` class. You need the JavaFX jar on the classpath. See [here](http://stackoverflow.com/questions/8241525/how-to-use-javafx-2-sdk-in-eclipse). – Reimeus Feb 22 '14 at 03:48
0

Try something like this:

    JFrame frame = new JFrame();
    JTextField field = new JTextField();
    frame.add(field);
    frame.pack();
    frame.setVisible(true);

    JEditorPane pane = new JEditorPane();
    try {
        pane.setPage(field.getText());
        ...
    }
    catch (IOException e) {
        pane.setContentType("text/html");
        pane.setText("<html>Could not load ");
    }
...
Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45