hai
i want to embed browser in my java program
i google and find JDIC.I dont know how to use it.
So i really wanna ask can i use Jdic to emmbed browser in my java program.
Is there any good tutorial.
.

Recommended Answers

All 2 Replies

Don't now of ones already make but with a JEditorPane and an HyperlinkListener shouldn't be complicated to write one

public class WebBrowser extends JPanel implements ActionListener, HyperlinkListener {

	private JTextField url;
	private JButton button;
	private JEditorPane editorPane;

	public WebBrowser()
	{
		super(new BorderLayout());
		url = new JTextField(30);
		url.setText("http://");

		button = new JButton("Load");
		button.addActionListener(this);

		editorPane = new JEditorPane();
		editorPane.setEditable(false);
		editorPane.addHyperlinkListener(this);

		add(editorPane, BorderLayout.CENTER);

		JPanel p = new JPanel();
		p.add(new JLabel("URL"));
		p.add(url);
		p.add(button);
		add(p, BorderLayout.SOUTH);
	}

	// "load" button clicked
	public void actionPerformed(ActionEvent e) {
		try
		{
			editorPane.setPage(url.getText());
		}
		catch(Exception err)
		{
			editorPane.setText("Error: " + err + " don't forget http://");
		}
	}

	public void hyperlinkUpdate(HyperlinkEvent e) {

		if(e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
			return;

		try
		{
			url.setText(e.getURL().toString());
			editorPane.setPage(e.getURL());
		}
		catch(IOException err)
		{
			editorPane.setText("Error: " + err);
		}


	}

	// to test the whole thing
	public static void main(String [] args)
	{
		JFrame frame = new JFrame("Browser");
		frame.add(new JScrollPane(new WebBrowser()));
		frame.setBounds(10, 10, 500, 500);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.setVisible(true);
	}


}

yes i have tried JEditorPane.
It is not working , java script is not handle correctly .display is very bad. so i think i use gecko or jdic in project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.