Pour des fins d'essai, je suis en train d'ajouter une petite image à côté de chaque ligne de document avec ce code:affichage image HTML en utilisant JTextPane avec HTMLEditorKit
kit.insertHTML(doc, doc.getLength(), "<IMG SRC=file://res/picture.png>", 0, 0, HTML.Tag.IMG);
Mon problème est que je ne vois cela, pas d'image juste un cadre pour elle:
je aurais pu me le pathing mal, mais cela devrait être correct de ce que je sais:
C'est un peu plus de code o f ma méthode:
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();
}
}
Est-ce que quelqu'un sait pourquoi tout ce que je peut voir le petit cadre de l'image, ai-je oublié quelque chose? Merci d'avance! Si vous avez besoin de plus de code, faites le moi savoir!