Reputation: 70
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
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
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