Era più per curiosità che altro, qualche tempo fa ci avevo messo mano anch'io, semplicemente ripulendo un po' il codice che trovi nel tutorial di Swing sul sito della sun.
codice:
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*; //for layout managers and more
import java.awt.event.*; //for action events
import java.net.URL;
import java.io.IOException;
public class TextSamplerDemo extends JPanel implements ActionListener {
private JLabel address = new JLabel("Address: ");
private JTextField addr = new JTextField(100);
private JButton go = new JButton("Go!");
private JEditorPane editorPane;
public void actionPerformed (ActionEvent ae) {
try {
editorPane.setPage(new URL(addr.getText()));
}
catch (Exception e) {
System.out.println(e.toString());
}
validate();
}
public TextSamplerDemo() {
setLayout(new BorderLayout());
JPanel navbar = new JPanel();
navbar.add(address);
navbar.add(addr);
navbar.add(go);
go.addActionListener(this);
add(navbar, BorderLayout.NORTH);
editorPane = createEditorPane();
JScrollPane editorScrollPane = new JScrollPane(editorPane);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
editorScrollPane.setPreferredSize(new Dimension(800, 600));
editorScrollPane.setMinimumSize(new Dimension(10, 10));
add(editorScrollPane, BorderLayout.CENTER);
}
private JEditorPane createEditorPane() {
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
try {
java.net.URL helpURL = new URL("http://www.google.it");
try {
editorPane.setPage(helpURL);
}
catch (IOException e) {
System.err.println("Attempted to read a bad URL: " + helpURL);
}
}
catch (Exception e) {System.out.println("Azz: "+e.toString());}
return editorPane;
}
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("TextSamplerDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new TextSamplerDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Come potrai vedere, alcune cose sono mostrate decentemente, altre affatto... c'è da gestire javascript da zero ad esempio (prova ad aprire yahoo.com). Se lo devi usare per mostrare documentazione con formattazione semplice però secondo me te la sbrighi con poco.
Ciao