Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/05/2008, 10:13
jnimo
 
Fecha de Ingreso: mayo-2008
Mensajes: 1
Antigüedad: 16 años
Puntos: 0
JEditorPane y multiples fonts

Saludos y gracias por leerme, tengo un problema con JEditorPane, quiero leer una pagina web completa en el JeditorPane con multiples fonts, pero no me funciona, pone solo un tipo de font, aqui pongo el ejemplo cutre con el que estoy intentando

pagina que estoy usando:

<body bgcolor="#FFFFFF"><div style="width:400px; ">
<p style="text-align:left; ">
<font style="letter-spacing: 0px; color: #0B333C; font-size: 100px; font-family: Verdana; "/>
</p>
<p style="text-align:left; ">
<font style="letter-spacing: 0px; color: #0B333C; font-size: 70px; font-family: Arial; ">Enter </font><br>
<font style="letter-spacing: 0px; color: #0B333C; font-size: 70px; font-family: Times; ">Enter </font>
<br><font face='sans serif' >Enter</font>
</p>
<p style="text-align:left; ">
<font style="letter-spacing: 0px; color: #0B333C; font-size: 5px; font-family: Verdana; "/>
</p>
</div>

codigo java:

import java.awt.*;
import java.awt.image.*;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.io.*;

public abstract class WebImage {

static class Kit extends HTMLEditorKit {
// Override createDefaultDocument to force synchronous loading
public Document createDefaultDocument() {
HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
doc.setTokenThreshold(Integer.MAX_VALUE);
doc.setAsynchronousLoadPriority(-1);
return doc;
}
}

public static BufferedImage create(String src, int width, int height) {
BufferedImage image = null;

JEditorPane pane = new JEditorPane();
Kit kit = new Kit();
pane.setEditorKit(kit);
pane.setEditable(false);
pane.setMargin(new Insets(0,0,0,0));
pane.putClientProperty(JEditorPane.W3C_LENGTH_UNIT S, Boolean.TRUE);
pane.putClientProperty(JEditorPane.HONOR_DISPLAY_P ROPERTIES, Boolean.TRUE);
//pane.
try {
pane.setPage(src);
/*pane.setContentType("text/html");
pane.setText("<font face='sans serif'> </font>");
pane.setCaretPosition(0);*/
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
Container c = new Container();
SwingUtilities.paintComponent(g, pane, c, 0, 0, width, height);
g.dispose();
} catch (Exception e) {
System.out.println(e);
}
return image;
}

public static void main(String[] args) {
BufferedImage image = WebImage.create("http://localhost/text1376.html", 2000, 2500);
//
File f = new File("/home/jimmy/prueba22.png");
try
{
ImageIO.write(image, "png", f);
}
catch(Exception e)
{

}

}

me hace todo lo requerido pero no con los tipos de font que tengo en el html, alguna idea?