ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
414
414
EMPFEHLEN
-
Hallo zusammen,
ich setze wie folgt einen HTML-Text auf einen JEditorPane:
Code :1 2 3
htmlPane.setContentType("text/html"); htmlPane.setText(quellcode.toString()); setVisible(true);
Das JFrame wird auch sichtbar, allerdings bleibt der JEditorPane grau. Ich habe im Quellcode einfach mal die Seite von google hinterlegt. Mache ich hier was falsch?
-
Hi,
also bei mir funktioniert das so:
Code java:1 2 3 4 5 6 7 8 9 10
String quellcode="<h3>TEST</h3>"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane htmlPane = new JEditorPane(); htmlPane.setContentType("text/html"); htmlPane.setText(quellcode.toString()); frame.getContentPane().add(htmlPane); frame.pack(); frame.setVisible(true);
Gruß
joschi
-
Hallo Joschi,
hast recht. Mit diesem "simplen" HTML-Konstrukt klappt es perfekt. Aber versuch mal bitte z.B. den Quellcode der google.de Seite reinzuschreiben. Das klappt leider nicht.
Ciao
Maik
-
Hi Maik,
hast Recht, mit Google funktioniert es leider nicht.
Liegt vermutlich am HTMLEditorKit, das ist nicht so toll, was das Rendern von HTML Seiten angeht.
Sorry, dann kann ich Dir leider auch nicht weiterhelfen
Gruß
joschi
-
Hi Maik,
habs mir nochmal angeschaut.
Der Parser des HTMLEditorKit scheint mit den <meta> Tags nicht zurecht zu kommen und wirft eine Exception: javax.swing.text.ChangedCharSetException.
Nimmt man die <meta> Tags raus, wird die Seite wenigstens gerendert. Ist aber immer noch nicht schön.
Code java: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
HTMLDocument html = new HTMLDocument(); HTMLEditorKit kit = new HTMLEditorKit(); URL url = new URL("http://www.google.de/"); html.setBase(url); kit.read(removeMetaTags(url.openStream()), html, 0); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane htmlPane = new JEditorPane(); htmlPane.setContentType("text/html"); htmlPane.setDocument(html); frame.getContentPane().add(htmlPane); frame.pack(); frame.setVisible(true); /* --------------------------------------------- */ private InputStream removeMetaTags(InputStream in) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; while ((line = br.readLine()) != null) { line = line.toLowerCase().replaceAll("<meta .*?>", ""); bos.write((line + "\n").getBytes()); } br.close(); return new ByteArrayInputStream( bos.toByteArray()); }
Gruß
joschiGeändert von joschi70 (01.10.08 um 08:03 Uhr)
Ähnliche Themen
-
HTMLLoader bleibt grau bei BitmapData draw
Von BMo im Forum Adobe Flex & AIRAntworten: 3Letzter Beitrag: 17.03.09, 11:09 -
50 % Grau ist nicht 50 % Grau
Von nanda im Forum PhotoshopAntworten: 3Letzter Beitrag: 23.04.08, 22:07 -
3D Fenster bleibt grau
Von Caliban2k6 im Forum Cinema 4DAntworten: 6Letzter Beitrag: 21.06.07, 16:40 -
grau weiss grau tabelle?
Von asdfg im Forum PHPAntworten: 19Letzter Beitrag: 05.03.06, 10:44





Zitieren
Login





