0

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.
.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by usiyalla
0

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


}

Edited by pbl: n/a

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.