Fusion
Fusion

Reputation: 70

Webpage won't work using JEdior Pane

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!

Upvotes: 0

Views: 80

Answers (2)

Reimeus
Reimeus

Reputation: 159844

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)

Upvotes: 1

Alvin Bunk
Alvin Bunk

Reputation: 7764

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 ");
    }
...

Upvotes: 0

Related Questions