1

我正在尝试在我的 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);
    }
}

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

希望可以有人帮帮我。

4

1 回答 1

0

看一下Flying-Saucer,它可以将 Html 渲染为 Swing:

Flying Saucer 采用 XML 或XHTML并对其应用符合 CSS 2.1 的样式表,以便使用Swing或 SWT 呈现为 PDF(通过 iText)、图像和屏幕上。

这里有一些截图可用:https ://code.google.com/p/flying-saucer/wiki/Screenshots

于 2013-02-10T18:54:48.647 回答