wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Creating Browser Window .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating Browser Window .." Watch "Creating Browser Window .." New topic

Creating Browser Window ..

Rajesh Nair

Joined: Aug 22, 2001
Posts: 9
Hi all,
I was trying to create a small browser window , by doing some modifications in the coding i have got from some site.But the program is showing an IOException in the coding part which is shown as bold and it could not connect with the URL specified.
I am using DSL connection and i am working through proxy server.
If it is the problem , How can i specify the Proxy Server IPAddress in the program ??
Thanx in Advance
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
/** Very simplistic "Web browser" using Swing. Supply a URL on the
* command line to see it initially, and to set the destination
* of the "home" button.mn
* 1998 Marty Hall, http://www.apl.jhu.edu/~hall/java/
public class Browser extends JFrame implements HyperlinkListener,
ActionListener {
public static void main(String[] args) {
if (args.length == 0)
new Browser("http://www.apl.jhu.edu/~hall/");
new Browser(args[0]);
private JIconButton homeButton;
private JTextField urlField;
private JEditorPane htmlPane;
private String initialURL;
public Browser(String initialURL) {
super("Simple Swing Browser");
this.initialURL = initialURL;
//addWindowListener(new ExitListener());
JPanel topPanel = new JPanel();
homeButton = new JIconButton("home.gif");
JLabel urlLabel = new JLabel("URL:");
urlField = new JTextField(30);
getContentPane().add(topPanel, BorderLayout.NORTH);
try {
htmlPane = new JEditorPane(initialURL);
JScrollPane scrollPane = new JScrollPane(htmlPane);
getContentPane().add(scrollPane, BorderLayout.CENTER);
} catch(IOException ioe) {
warnUser("Can't build HTML pane for " + initialURL
+ ": " + ioe);
Dimension screenSize = getToolkit().getScreenSize();
int width = screenSize.width * 8 / 10;
int height = screenSize.height * 8 / 10;
setBounds(width/8, height/8, width, height);

public void actionPerformed(ActionEvent event) {
String url;
if (event.getSource() == urlField)
url = urlField.getText();
else // Clicked "home" button instead of entering URL
url = initialURL;
try {
htmlPane.setPage(new URL(url));
} catch(IOException ioe) {
warnUser("Can't follow link to " + url + ": " + ioe);
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
} catch(IOException ioe) {
warnUser("Can't follow link to "
+ event.getURL().toExternalForm() + ": " + ioe);

private void warnUser(String message) {
JOptionPane.showMessageDialog(this, message, "Error",

class JIconButton extends JButton {
public JIconButton(String file) {
super(new ImageIcon(file));

[This message has been edited by Rajesh Nair (edited August 29, 2001).]
cardwell cupp
Ranch Hand

Joined: Aug 16, 2001
Posts: 66

What exactly does the IOException break down to?
When I ran mine, I got a IOExeption due to a malformed url, make sure to include the http://. I will test your code and see if I can't debug it.
I agree. Here's the link: http://aspose.com/file-tools
subject: Creating Browser Window ..
Similar Threads
UnknownHostException in JEditorPane
JSplitPane, some help please
Help building a JAR file...
Wrong font size in JEditorpane
Local HTTP file question