gpt4 book ai didi

java - 在Java中加载和显示HTML+CSS

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:59 24 4
gpt4 key购买 nike

我正在尝试在我的 Java 程序中显示 Xbox Gamer Card:这是一张 GamerCard:http://gamercard.xbox.com/de-DE/anybody.card

目前我有以下内容:

import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLEditorKit;

public class CardLoader extends JEditorPane {
private static final long serialVersionUID = 1L;
private static final String[] card = { "http://gamercard.xbox.com/de-DE/", ".card" };
private static final String styleSheetLink = "http://gamercard.xbox.com/Content/Gamercard/default/gamercard.css";

public CardLoader(String username) {
HTMLEditorKit kit = new HTMLEditorKit();
this.setEditable(false);
this.setPreferredSize(new Dimension(200, 135));

kit.getStyleSheet().addRule(URLCaS(styleSheetLink));
this.setEditorKit(kit);

try {
this.setPage(card[0] +username +card[1]);
} catch (Exception e) {
e.printStackTrace();
}
}

String URLCaS(String url){
InputStream in = null;
String returner = new String();
try {
in = new URL(url).openStream();
InputStreamReader inR = new InputStreamReader( in );
BufferedReader buf = new BufferedReader( inR );
String line;

while ( ( line = buf.readLine() ) != null ) {
returner += line + "\n";
}

in.close();
} catch (Exception e){
e.printStackTrace();
}
return returner.substring(3);
}
}

看起来,它可以应用样式表,但不正确。

希望有人能帮助我。

最佳答案

看看Flying-Saucer ,它可以将 Html 渲染到 Swing:

Flying Saucer takes XML or XHTML and applies CSS 2.1-compliant stylesheets to it, in order to render to PDF (via iText), images, and on-screen using Swing or SWT.

此处提供了一些屏幕截图:https://code.google.com/p/flying-saucer/wiki/Screenshots

关于java - 在Java中加载和显示HTML+CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14034024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com