[Q#1988202][A#1988273] How do I get a webpage to open up in a frame?
https://stackoverflow.com/q/1988202
How do I get a webpage to open up in a frame? (I'm using netbeans and java) e.g in a html page you can use and it will display google in the frame. I don't want it to open a browser, just to open up within the frame. How can I do that?
Answer
https://stackoverflow.com/a/1988273
Here is a quick example of how to load google with the JEditorPane. I hope this is what you are looking for, but I'm still not 100% sure what exactly you want. If you could provide a bit more information about what you are doing I would be able to help you more.
APIzation
import javax.swing.*;
public class GetWebPage {
public static void main(String args[]) throws Exception {
JEditorPane website = new JEditorPane("http://www.google.com/");
website.setEditable(false);
JFrame frame = new JFrame("Google");
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
}
package com.stackoverflow.api;
import javax.swing.*;
public class Human1988273 {
public static JFrame getWebPage(String title, String url) throws Exception {
JEditorPane website = new JEditorPane(url);
website.setEditable(false);
JFrame frame = new JFrame(title);
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
return frame;
}
}
package com.stackoverflow.api;
import javax.swing.*;
/**
* How do I get a webpage to open up in a frame?
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/1988273">https://stackoverflow.com/a/1988273</a>
*/
public class APIzator1988273 {
public static void getWebpage() throws Exception {
JEditorPane website = new JEditorPane("http://www.google.com/");
website.setEditable(false);
JFrame frame = new JFrame("Google");
frame.add(new JScrollPane(website));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
}