1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Exemple extends JFrame {
public Exemple() {
super("JEditorPane");
pane = new JEditorPane();
pane.setEditable(false);
getContentPane().add(new JScrollPane(pane), "Center");
String url = "http://www.gnu.org";
try{
pane.setPage(url);
}
catch (IOException e) {
JOptionPane.showMessageDialog(pane, new String[] {
"Unable to open file", url }, "File Open Error",
JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
JFrame f = new Exemple();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(500, 400);
f.setVisible(true);
}
private JEditorPane pane;
} |
Partager