Link to home
Start Free TrialLog in
Avatar of gujuraja143
gujuraja143

asked on

Loading HTML

After loading my Java Program, I want to click a button, like my help menu button, and load an HTML document or a browser with some information thats already there, like a help file.

How would I do this?  How would I point my actionlistener to that html page and load that html page, my Program is not an applet, its a Java program.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ovi
Ovi

/*
 * Created on Mar 25, 2003
 *
 * To change this generated comment go to
 * Window>Preferences>Java>Code Generation>Code Template
 */
package tests.swing.text;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

/**
 * @author ovi
 */
public class URLBrowser {

     public static void main(String[] args) {
          JFrame f = new JFrame();
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setSize(100, 80);
          f.setLocation(50, 100);
          f.getContentPane().setLayout(new BorderLayout());

          JButton help = new JButton("Help");
          help.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    JFrame helpFrame = new JFrame();
                    helpFrame.getContentPane().setLayout(new BorderLayout());
                    JEditorPane browser = new JEditorPane();
                    browser.setEditable(false);
                    try {
                         browser.setPage("https://www.experts-exchange.com");
                    } catch (Exception ex) {
                         ex.printStackTrace();
                    }
                    helpFrame.getContentPane().add(new JScrollPane(browser), BorderLayout.CENTER);
                    helpFrame.setSize(500, 500);
                    helpFrame.setLocation(160, 100);
                    helpFrame.setVisible(true);
               }
          });

          f.getContentPane().add(help, BorderLayout.CENTER);
          f.setVisible(true);
     }
}
Yes JEditorPane can be used, but it is pretty limited in it's HTML support.
... or if this is not enough you could use JavaHelp.