テスト目的で、次のコードを使用して、ドキュメントの各行の横に小さな画像を追加しようとしています:
kit.insertHTML(doc, doc.getLength(), "<IMG SRC=file://res/picture.png>", 0, 0, HTML.Tag.IMG);
私の問題は、私が見るのはこれだけで、写真はフレームだけではないということです:
パスが間違っている可能性がありますが、これは私が知っていることから正しいはずです:
これは私の方法のコードです:
public void addText(String text, boolean timestamp) {
long timeMS = System.currentTimeMillis();
Date instant = new Date(timeMS);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String time = sdf.format(instant);
boolean shouldScroll = false;
try {
HTMLDocument doc = (HTMLDocument) getChat().getDocument();
HTMLEditorKit kit = (HTMLEditorKit) getChat().getEditorKit();
JScrollBar vsb = getChatScroller().getVerticalScrollBar();
BoundedRangeModel model = vsb.getModel();
if (model.getExtent() + model.getValue() == model.getMaximum())
shouldScroll = true;
kit.insertHTML(doc, doc.getLength(), timestamp ? time + ": " + text : text, 0, 0, null);
kit.insertHTML(doc, doc.getLength(), "<IMG SRC=file://res/picture.png>", 0, 0, HTML.Tag.IMG);
if (shouldScroll)
getChat().setCaretPosition(doc.getLength());
} catch (IOException | BadLocationException e) {
e.printStackTrace();
}
}
写真の小さなフレームしか見えない理由を誰か知っていますか? 何かを忘れたのですか? 前もって感謝します!さらにコードが必要な場合はお知らせください。